Skip to content

Instantly share code, notes, and snippets.

@shanelau
Created November 10, 2014 02:32
Show Gist options
  • Save shanelau/0fe1beae9b12a5c718d8 to your computer and use it in GitHub Desktop.
Save shanelau/0fe1beae9b12a5c718d8 to your computer and use it in GitHub Desktop.
时区转化 timezone translate
/**
*
* @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