2

Say please what is the best way to convert Sitecore datetime string (20170401T073000Z) to javascript Date object ?

1

1 Answer 1

2

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.