1

What is the difference between following date formats in javascript:

console.log(new Date('December 17, 1995'));  // 1
console.log(new Date('1995/11/17'));         // 2
console.log(new Date('1995-11-17T00:00:00'));// 3
console.log(new Date('1995-11-17 00:00:00'));// 4
console.log(new Date('1995-11-17'));         // 5

My understanding is that all are equivalent & we should be getting value as "Sun Dec 17 1995 00:00:00 GMT+0530 (India Standard Time)", for 1st to 4th we are getting desired value but in case of 5th we are getting value as "Fri Nov 17 1995 05:30:00 GMT+0530 (India Standard Time)".

Why there is difference of time in 4th & 5th? Please explain this behavior.

adhishspn
  • 99
  • 1
  • 2
  • 7
  • 2
    Possible duplicate of [different result for yyyy-mm-dd and yyyy/mm/dd in javascript when passed to "new Date"](https://stackoverflow.com/questions/30199130/different-result-for-yyyy-mm-dd-and-yyyy-mm-dd-in-javascript-when-passed-to-new) and [Why does Date.parse give incorrect results?](https://stackoverflow.com/questions/2587345) and [Why is YYYY-MM-DD != YYYY/MM/DD](https://stackoverflow.com/questions/34037057) – adiga Feb 14 '19 at 10:06
  • @adiga Got difference between 2nd & 5th but what is the difference between 4th & 5th? – adhishspn Feb 14 '19 at 10:28
  • 1
    Because, **date-only** forms are interpreted as a ***UTC time*** and **date-time** forms are interpreted as ***local time*** https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse#Date_Time_String_Format – adiga Feb 14 '19 at 10:44

0 Answers0