Forked from kejyun/javascript.date.timezone.trans.js
Last active
August 29, 2015 14:13
-
-
Save fallingfree/9efb5b2e08462c7ff97f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 新增當地時區的時間物件 | |
function DateTimezone(offset) { | |
// 建立現在時間的物件 | |
d = new Date(); | |
// 取得 UTC time | |
utc = d.getTime() + (d.getTimezoneOffset() * 60000); | |
// 新增不同時區的日期資料 | |
return new Date(utc + (3600000*offset)); | |
} | |
// 計算當地時區的時間 | |
function calcTime(city, offset) { | |
// 建立現在時間的物件 | |
d = new Date(); | |
// 取得 UTC time | |
utc = d.getTime() + (d.getTimezoneOffset() * 60000); | |
// 新增不同時區的日期資料 | |
nd = new Date(utc + (3600000*offset)); | |
// 顯示當地時間 | |
return "在 " + city + " 的本地時間是 " + nd.toLocaleString(); | |
} | |
console.log(calcTime('taipei' , 8)); | |
var date_taipei = DateTimezone(8); | |
console.log(date_taipei.toLocaleString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment