JavascriptでUnixTimeをDateへ変換する
実行結果:
1261825579 -> Sun Dec 27 05:06:19 UTC+0900 2009
サンプル:
http://www.casey.jp/samples/javascript/unixtime.html
http://www.casey.jp/samples/javascript/unixtime2date.html
スポンサードリンク
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script language="JavaScript" type="text/javascript"> <!-- function unixtimeToDate(ut, TZ) { var tD = new Date( ut * 1000 ); tD.setTime( tD.getTime() + (60*60*1000 * TZ) ); return tD; } function getUnixTime(){ return parseInt( (new Date)/1000 ); } function test(){ var TZ = +9; var oDate = unixtimeToDate(document.f1.ut.value, TZ); document.getElementById("view").innerHTML = oDate.toString(); } function test_onload(){ document.f1.ut.value = getUnixTime(); } --> </script> </head> <body onload="test_onload();"> <form name="f1"> <input type="text" name="ut" size="10" value="1261818168"> <input type="button" value="exec" onClick="test();"> </form> <div id="view"></div> </body> </html>
参考文献
- Unixtime Javascript Converter – Convert Unix-time to Date :
http://www.captain.at/review-unixtime-javascript.php - pythonとperlとphpとas3とjavascriptで日時計算 « taichino.com :
http://taichino.com/programming/794
コメント