How to change the format of:

--> var enterDate = '2016-01-15'; // to 2016-01-15T00:00:00.0000000+08:00 with JS syntax?

// I try these and none of these works out:

1) enterDate.format("yyyy-mm-ddT00:00:00.0000000+08:00");
console.log(enterDate);

2) enterDate.toLocaleFormat("%B %e, %Y %M:%S");

Thanks in advance.

Member Avatar for diafol
var dateString = '2016-01-15';
var d = new Date(dateString);
var output = d.getUTCFullYear() + "-" + ("0" + (d.getUTCMonth()+1)).slice(-2) + "-" + ("0" + d.getUTCDate()).slice(-2) + "T" + ("0" + d.getUTCHours()).slice(-2) + ":" + ("0" + d.getUTCMinutes()).slice(-2) + ":" + ("0" + d.getUTCSeconds()).slice(-2) + ("00" + d.getUTCMilliseconds()).slice(-3) + "0000+08:00";
console.log(output);

Not tested. You really want this to the closest 100 nanoseconds???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.