js unix时间戳转换
生活随笔
收集整理的這篇文章主要介紹了
js unix时间戳转换
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一、unix時(shí)間戳轉(zhuǎn)普通時(shí)間:
var unixtime=1358932051;
var unixTimestamp = new Date(unixtime* 1000);
commonTime = unixTimestamp.toLocaleString();
alert("普通時(shí)間為:"+commonTime);
二、普通時(shí)間轉(zhuǎn)unix時(shí)間戳
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(); //獲取當(dāng)前年份(2位)
myDate.getFullYear(); //獲取完整的年份(4位,1970-????)
myDate.getMonth(); //獲取當(dāng)前月份(0-11,0代表1月)
myDate.getDate(); //獲取當(dāng)前日(1-31)
myDate.getDay(); //獲取當(dāng)前星期X(0-6,0代表星期天)
myDate.getTime(); //獲取當(dāng)前時(shí)間(從1970.1.1開(kāi)始的毫秒數(shù))
myDate.getHours(); //獲取當(dāng)前小時(shí)數(shù)(0-23)
myDate.getMinutes(); //獲取當(dāng)前分鐘數(shù)(0-59)
myDate.getSeconds(); //獲取當(dāng)前秒數(shù)(0-59)
myDate.getMilliseconds(); //獲取當(dāng)前毫秒數(shù)(0-999)
myDate.toLocaleDateString(); //獲取當(dāng)前日期
var mytime=myDate.toLocaleTimeString(); //獲取當(dāng)前時(shí)間
myDate.toLocaleString( ); //獲取日期與時(shí)間
?
轉(zhuǎn)載于:https://www.cnblogs.com/whlives/p/3881355.html
總結(jié)
以上是生活随笔為你收集整理的js unix时间戳转换的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: UVALive 6257 Chemist
- 下一篇: 把txt文件中的json字符串写到pli