Say please what is the best way to convert Sitecore datetime string (20170401T073000Z) to javascript Date object ?
1 Answer
JavaScript equivalent of ISO date format used in Sitecore is 2017-04-01T07:30:00Z
.
You first need to convert from 20170401T073000Z
to
2017-04-01T07:30:00Z
and then create new Date object:
var dateString = "20170401T073000Z";
// change string to "2017-04-01T07:30:00Z";
var formattedDateString = dateString.substr(0, 4)
+ "-" + dateString.substr(4, 2)
+ "-" + dateString.substr(6, 5)
+ ":" + dateString.substr(11, 2)
+ ":" + dateString.substr(13, 3);
// create date obj with Timezone info
var dateObj = new Date(formattedDateString);