Matěj Zmítko Matěj Zmítko - 5 months ago 44
Node.js Question

Nodejs how to get current day without timezone

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?

dan dan

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'


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.