I was wondering if I can remove the timezone from the date using javascript? I get the datetime on a json format, now I want to set it back but it returns more info of what I actually want/need.
What I have now is:
var d = new Date();
d.setTime(1432851021000);
document.write(d);
and the output is something like this:
Thu May 28 2015 16:10:21 GMT-0600 (CST)
Id like to show only until the hour, and remove GMT-0600 (CST).
I know javascript takes that depending on the current user's timezone, which is a problem, because the information could be saved on different countries.
I am trying to avoid to create the format using something like:
d.date() + "/" + d.month()...etc
Is there a better solution for this?
I believe d.toDateString() will output the format you're looking for.
var d = new Date();
d.setTime(1432851021000);
d.toDateString(); // outputs to "Thu May 28 2015"
d.toGMTString(); //outputs to "Thu, 28 May 2015 22:10:21 GMT"
Or even d.toLocaleString()
"5/28/2015, 6:10:21 PM"
There are lots of methods available to Date()
Using moment
moment().utcOffset(0, true).format()
From Javascript Date
var date = new Date();
Tue Sep 06 2021 00:00:00 GMT+0200
var isoDate = date.toISOString()
'2021-09-05T22:00:00.000Z'
var clearUTCDate = moment(date).utcOffset(0, true).format()
'2021-09-06T00:00:00Z'