Given date 2016-02-04. Suppose it will be February 4th, 2016. But when I use it new Date(), it returns as Wed Feb 03 2016 16:00:00 GMT-0800 (PST), rather than Thu Feb 04....
2016-02-04
new Date()
Wed Feb 03 2016 16:00:00 GMT-0800 (PST)
Thu Feb 04...
Below I literally do everything:
var _entryDate = new Date("2016-02-04"); console.log(_entryDate); // Wed Feb 03 2016 16:00:00 GMT-0800 (PST)
Why is this happening and how do I get the desired result, which is February 4, and not the day before?
var dateArray = "2016-02-04".split("-"); var year = dateArray[0]; var month = parseInt(dateArray[1], 10) - 1; var date = dateArray[2]; var _entryDate = new Date(year, month, date); alert(_entryDate);
Removed unnecessary parseIntfor monthand yearas suggested by @RobG
parseInt
month
year
, Pointy ( ). , UTC . , Date Date, , . , Date .
, , UTC, . 8 .
, T00:00-0800 . , Date , .
T00:00-0800
Javascript Date . , .
Date
, , Javascript . , , US/Eastern ( "EST" ):
new Date('2016-02-04') //=> Wed Feb 03 2016 19:00:00 GMT-0500 (EST) - midnight UTC new Date(2016,2,4) //=> Fri Mar 04 2016 00:00:00 GMT-0500 (EST) - midnight EST
:
new Date('2016-02-04T00:00:00-05:00')
, . , , , .
This is because the date is stored (and parsed) in UTC, but displayed in your local time zone. To display the correct date, you can use
new Date("2016-02-04").toISOString()
Source: https://habr.com/ru/post/1627321/More articles:jq: How to print quotes to the original output in windows - jqAngularjs: use configuration for only one controller - angularjshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1627318/send-message-from-ios-today-widget-to-app&usg=ALkJrhjkxqyefI6hi3w_4BbIChv6slxwlgЕсть ли способ вернуть определение функций в Elixir - elixirAre metadata or attributes allowed in the Golang? - validationFinding a point on the surface based on arc length and direction / angle in Matlab - matlabF #: replace with .Replace ("oldValue", "newValue") - charUsing setInterval in Meteor with reaction - timerAdd control dependency after creating operations? - tensorflow"Unable to update request after slice has been done." Best practics? - pythonAll Articles