JavaScript處理時間與日期
js提供Date類型來處理日期和時間
<script type="text/javascript"> var date = new Date();document.writeln(date); //Thu Jan 08 2015 01:25:53 GMT+0800 (中國標準時間) document.writeln(Date.parse()); //NaN document.writeln(Date.parse('6/10/2014')); //1402329600000 毫秒數 document.writeln(Date.parse('Thu Jan 08 2015 01:25:53')); //1420651553000 毫秒數 document.writeln(Date.UTC()); //NaN //日期格式化方法 document.writeln('<br/>'); document.writeln(date.toDateString()); //Thu Jan 08 2015 document.writeln('<br/>') document.writeln(date.toTimeString()); //01:39:08 GMT+0800 (中國標準時間) document.writeln('<br/>') document.writeln(date.toLocaleDateString()); //2015年1月8日 document.writeln('<br/>') document.writeln(date.toLocaleTimeString()); //上午1:39:08 document.writeln('<br/>') document.writeln(date.toUTCString()); //Wed, 07 Jan 2015 17:39:08 GMT //一些set,get方法 </script></pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!