0

How I can create new Date() in utc timezone 0 in node.js?

console.log(new Date('02-28-2017')) //2017-02-27T22:00:00.000Z
console.log(new Date('02-28-2017').toUTCString()); //Mon, 27 Feb 2017 22:00:00 GMT
console.log(new Date(new Date('02-28-2017').toUTCString())); //Mon, 27 Feb 

i want to get:

console.log(new Date('02-28-2017')) //2017-02-28T00:00:00.000Z
Jackson
  • 884
  • 2
  • 13
  • 22
  • Possible duplicate of [How to use timezone offset in Nodejs?](http://stackoverflow.com/questions/10615828/how-to-use-timezone-offset-in-nodejs) – brightDot Feb 28 '17 at 20:16
  • 2
    Possible duplicate of [create javascript date UTC](http://stackoverflow.com/questions/13364036/create-javascript-date-utc) – JJJ Feb 28 '17 at 20:18
  • let dt = new Date(Date.UTC(2017, 1, 28)); Possible duplicate of create javascript date UTC – JJJ - it works, thx – Jackson Feb 28 '17 at 20:42

2 Answers2

0

You could simple append the string "GMT" to the end of your date to get a GMT date:

new Date('02-28-2017 GMT')
// "Tue, 28 Feb 2017 00:00:00 GMT"

Is that what you're looking for?

Dana Woodman
  • 4,148
  • 1
  • 38
  • 35
  • Why the downvote? UTC timezone 0 is in fact GMT. Appending GMT to a non-timezone date in JS will give you a date in the GMT timezone. – Dana Woodman Jul 02 '20 at 16:27
-3
let dt = new Date('02-28-2017');
dt.setUTCHours(0);
dt.setUTCMinutes(0);
dt.setUTCSeconds(0);
dt.setUTCMilliseconds(0);
console.log(dt.toISOString());
jake_nerdnest
  • 402
  • 4
  • 10
  • 1
    I don't know, who minus your answer, but it's not work. console.log(dt); //2017-02-27T00:00:00.000Z but i need 2017-02-28 – Jackson Feb 28 '17 at 20:38