日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達者為師

網(wǎng)站首頁 編程語言 正文

1.把字符串轉(zhuǎn)化為時間戳,再將時間戳轉(zhuǎn)化為Date對象 /** *@parame time = 2016-12-12 19:41:59 * 或者2016

作者:ShangQuan2012 更新時間: 2022-01-16 編程語言

1、當前時間換時間戳

var timestamp = parseInt(new Date().getTime()/1000);    // 當前時間戳
document.write(timestamp);

?

2、當前時間換日期字符串

var now = new Date();
var yy = now.getFullYear();      //
var mm = now.getMonth() + 1;     //
var dd = now.getDate();          //
var hh = now.getHours();         //
var ii = now.getMinutes();       //
var ss = now.getSeconds();       //
var clock = yy + "-";
if(mm < 10) clock += "0";
clock += mm + "-";
if(dd < 10) clock += "0";
clock += dd + " ";
if(hh < 10) clock += "0";
clock += hh + ":";
if (ii < 10) clock += ‘0‘; 
clock += ii + ":";
if (ss < 10) clock += ‘0‘; 
clock += ss;
document.write(clock);     //獲取當前日期

?

3、日期字符串轉(zhuǎn)時間戳

var date = ‘2015-03-05 17:59:00.0‘;
date = date.substring(0,19);    
date = date.replace(/-/g,‘/‘); 
var timestamp = new Date(date).getTime();
document.write(timestamp);

?

4、時間戳轉(zhuǎn)日期字符串

var timestamp = ‘1425553097‘;
var d = new Date(timestamp * 1000);?? ?//根據(jù)時間戳生成的時間對象
var date = (d.getFullYear()) + "-" +
?? ??? ??? (d.getMonth() + 1) + "-" +
?? ??? ??? (d.getDate()) + " " +
?? ??? ??? (d.getHours()) + ":" +
?? ??? ??? (d.getMinutes()) + ":" +
?? ??? ??? (d.getSeconds());
document.write(date);
轉(zhuǎn)自http://www.mamicode.com/info-detail-500319.html
非常感謝

原文鏈接:https://blog.csdn.net/ShangQuan2012/article/details/53586975

欄目分類
最近更新