Timestamps JavaScript และสตริงวันที่แปลงรหัสให้กันและกัน (Super Simple)
<html xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> วันที่ ()); timestamp = timestamp/ 1,000; // timestamp ปัจจุบันคือ: 1403149534console.log ("Timestamp ปัจจุบันคือ:" + timestamp); // รับ timestamp ในรูปแบบเวลาที่กำหนด 1000; // 2014-07-10 การประทับเวลาของ 10:21:12 คือ: 1404958872 console.log (Stringtime + "timestamp:" + timestamp2); // เปลี่ยนเวลาปัจจุบันเป็นสตริงเวลา var timestamp3 = 140305804; console.log (newdate.todatestring ()); // พุธ, 18 มิ.ย. 2014 02:33:24 gmt console.log (newdate.togmtstring ()); // 2014-06-18t02: 33: 24.000zconsole.log console.log (newdate.tojson ()); // 18 มิถุนายน 2014 console.log (newdate.tolocaledatestring ()); // 18 มิถุนายน 2014 เวลา 10:33:24 AM console.log (newdate.tolocalestring (); 18 2014 10:33:24 GMT+0800 (เวลามาตรฐานจีน) คอนโซลล็อก (newdate.toString ()); // 10:33:24 GMT+0800 (เวลามาตรฐานจีน) คอนโซล (Newdate.Totimestring (); gmtconsole.log (newdate.toutcstring ()); date.prototype.format = function (รูปแบบ) {var date = {"m+": this.getMonth ()+1, "d+": this.getDate (), "h+": นี่ "q+": math.floor ((this.getMonth ()+3) / 3), "s+": this.getmilliseconds ()}; if (/(y+)/i.test(format)) {format = format.replace (regexp. $ 1, (this.getlyear () + '') .substr (4 - regexp. $ 1.length)); } สำหรับ (var k ในวันที่) {ถ้า (ใหม่ regexp ("(" + k + ")"). ทดสอบ (รูปแบบ)) {format = format.replace (regexp. $ 1, regexp. $ 1.length == 1? วันที่ [k]: ("00" + วันที่ [k]) }} return format;} console.log (newdate.format ('yyyy-mm-dd h: m: s'))); </script>ด้านบนเป็นเนื้อหาที่สมบูรณ์ของรหัสการแปลงเวลา JavaScript และรหัสการแปลงสตริงวันที่ (ง่ายสุด) นำมาให้คุณโดยตัวแก้ไข ฉันหวังว่าทุกคนจะสนับสนุน wulin.com ~