js unix时间戳转换
生活随笔
收集整理的這篇文章主要介紹了
js unix时间戳转换
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一、unix時間戳轉(zhuǎn)普通時間:
var unixtime=1358932051;
var unixTimestamp = new Date(unixtime* 1000);
commonTime = unixTimestamp.toLocaleString();
alert("普通時間為:"+commonTime);
二、普通時間轉(zhuǎn)unix時間戳
var str ="2013-01-01 00:00:00";
str = str.replace(/-/g,"/");
var date = new Date(str);
var humanDate = new Date(Date.UTC(date.getFullYear(),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(), date.getSeconds()));
alert(humanDate.getTime()/1000 - 8*60*60);
var myDate = new Date();
myDate.getYear(); //獲取當前年份(2位)
myDate.getFullYear(); //獲取完整的年份(4位,1970-????)
myDate.getMonth(); //獲取當前月份(0-11,0代表1月)
myDate.getDate(); //獲取當前日(1-31)
myDate.getDay(); //獲取當前星期X(0-6,0代表星期天)
myDate.getTime(); //獲取當前時間(從1970.1.1開始的毫秒數(shù))
myDate.getHours(); //獲取當前小時數(shù)(0-23)
myDate.getMinutes(); //獲取當前分鐘數(shù)(0-59)
myDate.getSeconds(); //獲取當前秒數(shù)(0-59)
myDate.getMilliseconds(); //獲取當前毫秒數(shù)(0-999)
myDate.toLocaleDateString(); //獲取當前日期
var mytime=myDate.toLocaleTimeString(); //獲取當前時間
myDate.toLocaleString( ); //獲取日期與時間
?
轉(zhuǎn)載于:https://www.cnblogs.com/whlives/p/3881355.html
總結(jié)
以上是生活随笔為你收集整理的js unix时间戳转换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UVALive 6257 Chemist
- 下一篇: cf配置要求高不高?