如何将JS时间戳转换成yyyy-mm-dd格式的日期?

2026-04-06 11:121阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

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

如何将JS时间戳转换成yyyy-mm-dd格式的日期?

javascriptjs时间转换工具var format=function(time, format) { var t=new Date(time); var tf=function(i) { return (i + 10 > 99 ? '0' : '') + i; }; return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a) { switch (a) { case 'yyyy': return tf(t.getFullYear()); case 'MM': return tf(t.getMonth() + 1); case 'dd': return tf(t.getDate()); case 'HH': return tf(t.getHours()); case 'mm': return tf(t.getMinutes()); case 'ss': return tf(t.getSeconds()); } });};

如何将JS时间戳转换成yyyy-mm-dd格式的日期?

js时间戳转换yyyy-mm-dd.txt

var format = function(time, format) { var t = new Date(time); var tf = function(i) { return (i < 10 ? '0': '') + i }; return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a) { switch (a) { case 'yyyy': return tf(t.getFullYear()); break; case 'MM': return tf(t.getMonth() + 1); break; case 'mm': return tf(t.getMinutes()); break; case 'dd': return tf(t.getDate()); break; case 'HH': return tf(t.getHours()); break; case 'ss': return tf(t.getSeconds()); break; }; }); }; 用法: format(Date, 'yyyy-MM-dd HH:mm:ss'); 如果时间戳没有时分秒 ,又不写格式,返回 yyyy-MM-dd;

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

如何将JS时间戳转换成yyyy-mm-dd格式的日期?

javascriptjs时间转换工具var format=function(time, format) { var t=new Date(time); var tf=function(i) { return (i + 10 > 99 ? '0' : '') + i; }; return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a) { switch (a) { case 'yyyy': return tf(t.getFullYear()); case 'MM': return tf(t.getMonth() + 1); case 'dd': return tf(t.getDate()); case 'HH': return tf(t.getHours()); case 'mm': return tf(t.getMinutes()); case 'ss': return tf(t.getSeconds()); } });};

如何将JS时间戳转换成yyyy-mm-dd格式的日期?

js时间戳转换yyyy-mm-dd.txt

var format = function(time, format) { var t = new Date(time); var tf = function(i) { return (i < 10 ? '0': '') + i }; return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a) { switch (a) { case 'yyyy': return tf(t.getFullYear()); break; case 'MM': return tf(t.getMonth() + 1); break; case 'mm': return tf(t.getMinutes()); break; case 'dd': return tf(t.getDate()); break; case 'HH': return tf(t.getHours()); break; case 'ss': return tf(t.getSeconds()); break; }; }); }; 用法: format(Date, 'yyyy-MM-dd HH:mm:ss'); 如果时间戳没有时分秒 ,又不写格式,返回 yyyy-MM-dd;