本文實(shí)例講述了JS實(shí)現(xiàn)將Asp.Net的DateTime Json類型轉(zhuǎn)換為標(biāo)準(zhǔn)時(shí)間的方法。分享給大家供大家參考,具體如下:
直接上例子,如下所示:
onload = function () { var thisDateText = '/Date(1401076829)/'; document.write(getLocalTime(thisDateText));};function getLocalTime(dateText) { dateText = dateText.replace("/Date(", "").replace(")/", ""); /* 需要注意的是: 不要把字符串中的Date(這樣的字符也傳進(jìn)去,要先處理一下,這樣很方便就能處理的 可以使用replace方法 如:replace("/Date(","").replace(")/",""); */ //返回 2014年5月26日 下午12:00 //return new Date(parseInt(dateText) * 1000).toLocaleString().replace(/:/d{1,2}$/, ' '); //返回 2014年5月26日 下午12:0 //return new Date(parseInt(dateText) * 1000).toLocaleString().substr(0, 17); //返回 2014-5-26 12:00:29 return new Date(parseInt(dateText) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ").replace(/上午/g, " ").replace(/下午/g, " ");}
PS:對(duì)JavaScript時(shí)間與日期顯示感興趣的朋友還可以參看本站在線工具:
Unix時(shí)間戳(timestamp)轉(zhuǎn)換工具:
http://tools.VeVB.COm/code/unixtime
在線世界各地時(shí)間查詢:
http://tools.VeVB.COm/zhuanhuanqi/worldtime
在線萬年歷日歷:
http://tools.VeVB.COm/bianmin/wannianli
網(wǎng)頁萬年歷日歷:
http://tools.VeVB.COm/bianmin/webwannianli
更多關(guān)于JavaScript相關(guān)內(nèi)容可查看本站專題:《JavaScript時(shí)間與日期操作技巧總結(jié)》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動(dòng)畫特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注