If the date is blank it is not a Number
var LifeCycleStart = item.DeviceAvailableFrom;
if (LifeCycleStart) LifeCycleStart=new Date(item.DeviceAvailableFrom);
And you don't need MomentJS
SharePoint adds a String.format
function
so you can use:
String.format('{0:dd}-{0:MM}-{0:yyyy}',new Date('2015-10-07T20:39:54Z'));
Note: String.format is defined in msajaxbundle.js
, loaded even before most of the JavaScript files so safe to use without SOD requirements or anything.
It was modelled after the C# and VB implementations,
so the MSDN documentation applies
(for the major part; it does not do the alignment stuff as that makes no sense in HTML)
String.format("{0:i}",new Date()); outputs: Wed Oct 07 2015 20:39:54 GMT+0200 (W. Europe Daylight Time)
String.format("{0:F}",new Date()); outputs: Wednesday, 07 October 2015 20:39:54
String.format("{0:f}",new Date()); outputs: Wednesday, 07 October 2015 20:39
String.format("{0:D}",new Date()); outputs: Wednesday, 07 October 2015
String.format("{0:s}",new Date()); outputs: 2015-10-07T20:39:54
String.format("{0:d}",new Date()); outputs: 10/07/2015
String.format("{0:dd}",new Date()); outputs: 07
String.format("{0:ddd}",new Date()); outputs: Wed
String.format("{0:dddd}",new Date()); outputs: Wednesday
String.format("{0:m}",new Date()); outputs: October 07
String.format("{0:M}",new Date()); outputs: October 07
String.format("{0:MM}",new Date()); outputs: 10
String.format("{0:MMM}",new Date()); outputs: Oct
String.format("{0:MMMM}",new Date()); outputs: October
String.format("{0:Y}",new Date()); outputs: 2015 October
String.format("{0:y}",new Date()); outputs: 2015 October
String.format("{0:yy}",new Date()); outputs: 15
String.format("{0:yyyy}",new Date()); outputs: 2015
String.format("{0:gg}",new Date()); outputs: A.D.
String.format("{0:T}",new Date()); outputs: 20:39:54
String.format("{0:t}",new Date()); outputs: 20:39
String.format("{0:HH}",new Date()); outputs: 20
String.format("{0:mm}",new Date()); outputs: 39
String.format("{0:ss}",new Date()); outputs: 54
It does more then just Dates:
MSDN String.format() Documentation
J5 iJS string format top20 iDate
DeviceAvailableFrom
has the right values but in the wrong format, you can wrap it with moment by passingvar wrapper = moment(LifeCycleStart);
on the next line.console.log( typeof item.DeviceAvailableFrom , item.DeviceAvailableFrom )
to check what you get from SP