如何获取并格式化显示当前时间?

更新于
2026-09-30 18:27:14
1阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计113个文字,预计阅读时间需要1分钟。

如何获取并格式化显示当前时间?

javascriptfunction getNowFormatDate() { var date=new Date(); var seperator1=-; var seperator2=:; var month=date.getMonth() + 1; var strDate=date.getDate(); if (month <10) month=0 + month; if (strDate < 10) strDate=0 + strDate; return date.getFullYear() + seperator1 + month + seperator1 + strDate + + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds();}

如何获取并格式化显示当前时间?

gistfile1.txt

function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); return currentdate; }

本文共计113个文字,预计阅读时间需要1分钟。

如何获取并格式化显示当前时间?

javascriptfunction getNowFormatDate() { var date=new Date(); var seperator1=-; var seperator2=:; var month=date.getMonth() + 1; var strDate=date.getDate(); if (month <10) month=0 + month; if (strDate < 10) strDate=0 + strDate; return date.getFullYear() + seperator1 + month + seperator1 + strDate + + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds();}

如何获取并格式化显示当前时间?

gistfile1.txt

function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); return currentdate; }