2008-12-17

JavaScript DateTime Local/UTC/TPE

注意剪貼後請將 "< " 空白移除
< script language=javaScript>
< ! -- Beginning of JavaScript ------------------------------------------------------
// -------- Get PC Local datetime --------
var Now = new Date()
var month = Now.getMonth() + 1
var day = Now.getDate()
var year = Now.getFullYear()
//document.write(month + "/" + day + "/" + year)
var hours=Now.getHours()
var minutes=Now.getMinutes()
var seconds=Now.getSeconds()
if (hours==0) hours=12
if (minutes<=9) minutes="0"+minutes
if (seconds<=9) seconds="0"+seconds
LocalDatetime= year+"/"+month+"/"+day+" "+hours+":"+minutes+":"+seconds
// -------- Get UTC datetime --------
var month = Now2.getUTCMonth() + 1
var day = Now2.getUTCDate()
var year = Now2.getUTCFullYear()
var hours=Now2.getUTCHours()
var minutes=Now2.getUTCMinutes()
var seconds=Now2.getUTCSeconds()
if (hours==0) hours=12
if (minutes<=9) minutes="0"+minutes
if (seconds<=9) seconds="0"+seconds
UTCdatetime= year+"/"+month+"/"+day+" "+hours+":"+minutes+":"+seconds
//-------- Get TPE datetime
var Now = new Date()
//var TPE = (Now.getTime() + (Now.getTimezoneOffset() * 60000) )
var utc_int = (Now.getTime() + (Now.getTimezoneOffset() * 60000) ) //msec integer
var NowUTC = new Date(utc_int )
var NowTPE = new Date(utc_int + (3600000* 8 )) // NowUTC add 8 hours
var month = NowTPE.getMonth() + 1
var day = NowTPE.getDate()
var year = NowTPE.getFullYear()
var hours=NowTPE.getHours()
var minutes=NowTPE.getMinutes()
var seconds=NowTPE.getSeconds()
if (hours==0) hours=12
if (minutes<=9) minutes="0"+minutes
if (seconds<=9) seconds="0"+seconds
TPEdatetime= year+"/"+month+"/"+day+" "+hours+":"+minutes+":"+seconds
// - End of JavaScript ------------------------------------------------------------ -->
< /script>

沒有留言: