如何根据当前时间戳进行时间格式化处理?

更新于
2026-09-29 13:36:04
1阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

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

如何根据当前时间戳进行时间格式化处理?

javascriptfunction times(d, sec) { var time; var date=new Date(d); var y=date.getFullYear(); var M=date.getMonth() + 1; M=M <10 ? '0' + M : M; var d=date.getDate(); d=d < 10 ? '0' + d : d; var h=date.getHours(); h=h + 1; time=y + '-' + M + '-' + d + ' ' + h + ':' + sec; return time;}

如何根据当前时间戳进行时间格式化处理?

gistfile1.txt

var times = function(d, sec) { var time; var date = new Date(d); var y = date.getFullYear(); var M = date.getMonth() + 1; M = M < 10 ? '0' + M : M; var d = date.getDate(); d = d < 10 ? '0' + d : d; var h = date.getHours(); h = h < 10 ? '0' + h : h; var m = date.getMinutes(); m = m < 10 ? '0' + m : m; var s = date.getSeconds(); s = s < 10 ? '0' + s : s; if (sec) { time = y + '-' + M + '-' + d + ' ' + h + ':' + m + ':' + s; } else { time = y + '-' + M + '-' + d + ' ' + h + ':' + m; } return time; };

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

如何根据当前时间戳进行时间格式化处理?

javascriptfunction times(d, sec) { var time; var date=new Date(d); var y=date.getFullYear(); var M=date.getMonth() + 1; M=M <10 ? '0' + M : M; var d=date.getDate(); d=d < 10 ? '0' + d : d; var h=date.getHours(); h=h + 1; time=y + '-' + M + '-' + d + ' ' + h + ':' + sec; return time;}

如何根据当前时间戳进行时间格式化处理?

gistfile1.txt

var times = function(d, sec) { var time; var date = new Date(d); var y = date.getFullYear(); var M = date.getMonth() + 1; M = M < 10 ? '0' + M : M; var d = date.getDate(); d = d < 10 ? '0' + d : d; var h = date.getHours(); h = h < 10 ? '0' + h : h; var m = date.getMinutes(); m = m < 10 ? '0' + m : m; var s = date.getSeconds(); s = s < 10 ? '0' + s : s; if (sec) { time = y + '-' + M + '-' + d + ' ' + h + ':' + m + ':' + s; } else { time = y + '-' + M + '-' + d + ' ' + h + ':' + m; } return time; };