Explain javascript Date () functions

Why does this happen when I have

var dt = new Date(2015, 6, 1); dt.toUTCString() 

My conclusion is Tue, 30 Jun 2015 23:00:00 GMT

and

 var dt = new Date(2015, 6, 2); dt.toUTCString() 

Wed, 01 Jul 2015 23:00:00 GMT

I'm obviously missing something here, I want every day of the month to be able to go through a loop and get Date() for that day

I don’t understand why, if the day is 1, he says the date is the 30th

+5
source share
3 answers

Javascript dates are always created with the local time zone. Using toUTCString converts the time in the Date object to UTC, and apparently in your case it means -1 hour. If you want to initialize a Date object with UTC time, use:

 var dt = new Date(Date.UTC(2015, 6, 1)); 
+3
source

The toUTCString () method converts a Date object to a string according to universal time.

Coordinated Universal Time (UTC) is the time set by the World Clock Standard.

Note: UTC is the same as GMT.

0
source

Try changing dt.toUTCString () in another function. There are many hours on the planet, for example, in America there are 5 hours, in Japan - 10 hours, etc. UTC is the time zone, try changing this.

0
source

All Articles