Reputation: 357
So I have a code in nodejs where I am getting a current date and time.
var timestamp = new Date().toString();
My output looks like this:
Wed Nov 09 2016 16:02:32 GMT+0100 (CET)
Can anybody please give me an advice how to get rid of GMT+0100 (CET)
in my output?
Upvotes: 1
Views: 3528
Reputation: 1984
If you want the UTC date/time then use toUTCString()
:
new Date().toUTCString();
// 'Wed, 09 Nov 2016 15:11:53 GMT'
If you want a standard UTC ISO8601 timestamp use toISOString()
:
new Date().toISOString()
// '2016-11-09T15:13:00.380Z'
If you literally just want to get rid of GMT+0100 (CET)
then:
new Date().toString().replace(' GMT+0100 (CET)', '');
// 'Wed Nov 09 2016 15:15:05'
or:
var now = new Date()
now.toString().substr(0, now.toString().indexOf(' GMT'))
// 'Wed Nov 09 2016 15:15:05'
Which will work for all timezones.
Upvotes: 3