//獲取當前時間戳(以s為單位)
vartimestamp
=date.parse(
newdate());
timestamp
=timestamp
/1000;//
當前時間戳為:1403149534
console.log(
"當前時間戳為:"+
timestamp);
//獲取某個時間格式的時間戳
varstringtime ="
2014-07-10 10:21:12";
vartimestamp2
=date.parse(
newdate(stringtime));
timestamp2
=timestamp2
/1000;//
2014-07-10 10:21:12的時間戳為:1404958872
console.log(stringtime +"
的時間戳為:"+
timestamp2);
//將當前時間換成時間格式字串
vartimesta***
=1403058804
;var
newdate
=new
date();
newdate.settime(timesta***
*1000
);//
wed jun 18 2014
console.log(newdate.todatestring());
//wed, 18 jun 2014 02:33:24 gmt
console.log(newdate.togmtstring());
console.log(newdate.toisostring());
console.log(newdate.tojson());
//2023年6月18日
console.log(newdate.tolocaledatestring());
//2023年6月18日 上午10:33:24
console.log(newdate.tolocalestring());
//上午10:33:24
console.log(newdate.tolocaletimestring());
//wed jun 18 2014 10:33:24 gmt+0800 (中國標準時間)
console.log(newdate.tostring());
//10:33:24 gmt+0800 (中國標準時間)
console.log(newdate.totimestring());
//wed, 18 jun 2014 02:33:24 gmt
console.log(newdate.toutcstring());
date.prototype.format
=function
(format) ;
if(/(y+)
/i.test(format))
for(
vark
indate)
}return
format;
}console.log(newdate.format(
'yyyy-mm-dd h:m:s
'));
script
>
java 時間戳與日期字串相互轉換
時間戳轉換成日期格式字串 param seconds 精確到秒的字串 param formatstr return public static string timestamp2date string seconds,string format if format null format.isemp...
java 時間戳與日期字串相互轉換
時間戳轉換成日期格式字串 param seconds 精確到秒的字串 param formatstr return public static string timestamp2date string seconds,string format if format null format.isemp...
java 時間戳與日期字串相互轉換
時間戳轉換成日期格式字串 param seconds 精確到秒的字串 param formatstr return public static string timestamp2date string seconds,string format if format null format.isemp...