Yesterday in a forum to see a friend asked JS how to get the GMT stamp.
Many friends first reaction is togmtstring ...
You can actually get Greenwich mean time, but not timestamp .
Although I do not have a good way to get one step, but at least to obtain, and share with you, let everyone cheap laugh.
getTimezoneOffset can get the offset of the current time zone, in minutes,
Our time zone is GMT+0800, so switching back should be-8 .
Convert to minutes-8 * = -480
getTimezoneOffset method to get the exactly-480
var dt = new Date;console.log (Dt.gettimezoneoffset ()); -480
We want to get the corresponding GMT stamp, just add-480 minutes.
var dt = new Date;dt.setminutes (dt.getminutes () + dt.gettimezoneoffset ()); Current time (minutes) + Time zone offset (minutes) console.log ("GMT Stamp:", Dt.gettime ()), Console.log ("Display in local time format:", dt.tolocalestring ());
Well, share this little bit of knowledge today.