1

Input: new Date("2013-03-28")

Output: Wed Mar 27 2013 17:00:00 GMT-0700 (PDT)

How do I get 28 instead of 27. Is this a javascript default issue?

sammiwei
  • 3,140
  • 9
  • 41
  • 53

1 Answers1

4

When using ISO-formatted dates, either all or in-part, the timezone may be assumed to be UTC.

console.log(new Date("2013-03-28").toUTCString());
// "Thu, 28 Mar 2013 00:00:00 GMT"

To create the date in local time, you can use a different overload of the constructor (note that month is 0-indexed, so 2 is March):

console.log(new Date(2013, 2, 28).toString());
// "Thu Mar 28 2013 00:00:00 GMT-0700 (...)"
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199