Created
November 10, 2014 02:32
-
-
Save shanelau/0fe1beae9b12a5c718d8 to your computer and use it in GitHub Desktop.
时区转化 timezone translate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param date need translate | |
* @returns {string} date | |
*/ | |
function calcTime(date) { | |
var d = new Date(date); | |
//Deal with dates in milliseconds for most accuracy | |
var utc = d.getTime() + (d.getTimezoneOffset() * 60000); | |
var newDateWithOffset = new Date(utc + (3600000*8)); | |
//This will return the date with the locale format (string), or just return newDateWithOffset | |
//and go from there. | |
return newDateWithOffset.toLocaleString(); | |
} | |
console.log(calcTime('2014-11-07T09:52:38.000Z')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment