Convert String To A Datetime Format Without Converting It To Your Local Time
Here's my Scenario: I have a value for DateTime in this Format only: '2017-05-01T07:40:00.000+10:00' but need this to convert to a Readable Date Time Format like this: eg. 05/0
Solution 1:
Try use with Regex
pattern /-|:|T/g
for split()
var t = "2017-05-01T07:40:00.000+10:00";
var s =t.split(/-|:|T/g).slice(0,5)
var c =parseInt(s[3]) > 12 ? parseInt(s[3])-12 : s[3];
var f =parseInt(s[3]) > 12 ? 'PM' : 'AM';
console.log(s[1]+'/'+s[2]+'/'+s[0]+' '+c+':'+s[4]+' '+f);
Solution 2:
You may refer to this post Stop javascript Date function from changing timezone offset
It also mentioned a sample on how to use 'moment' to pinpoint the datetime to the timezone you want to show (GMT+10).
Solution 3:
I think so this will help you.
var t = "2017-05-01T07:40:00.000Z";
var d = newDate(t); //using javascript Date object
Post a Comment for "Convert String To A Datetime Format Without Converting It To Your Local Time"