iT邦幫忙

1

Javascript 取得現在的年月日時分秒

  • 分享至 

  • xImage
  •  
var oDate = new Date();

var year = oDate.getFullYear();
var month = ( oDate.getMonth() + 1 );
var day = oDate.getDate();

var hours = oDate.getHours();
var minutes = oDate.getMinutes();
var seconds = oDate.getSeconds(); 


if (parseInt(month, 10) < 10) {
    month = "0" + parseInt(month, 10);
}
if (parseInt(day, 10) < 10) {
    day = "0" + parseInt(day, 10);
}
if (parseInt(hours, 10) < 10) {
    hours = "0" + parseInt(hours, 10);
}
if (parseInt(minutes, 10) < 10) {
    minutes = "0" + parseInt(minutes, 10);
}
if (parseInt(seconds, 10) < 10) {
    seconds = "0" + parseInt(seconds, 10);
}

var yyyymmddHHMMSS = year + "-" + month + "-" + day
    + " " + hours + ":" + minutes + ":" +seconds;

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

1
cho010012
iT邦新手 5 級 ‧ 2022-02-24 13:28:31

時間轉換
之前爬蟲的時候有遇到時區轉換的問題 可以參考這篇

大叮噹 iT邦新手 2 級 ‧ 2022-04-30 22:13:04 檢舉

謝謝你

我要留言

立即登入留言