`
ws110d
  • 浏览: 619 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

js 格式化日期

阅读更多
<html>
<body>
<script>
/// <summary>
/// 格式化显示日期时间
/// </summary>
/// <param name="x">待显示的日期时间,例如new Date()</param>
/// <param name="y">需要显示的格式,例如yyyy-MM-dd hh:mm:ss</param>
function date2str(x,y) {
var z = {M:x.getMonth()+1,d:x.getDate(),h:x.getHours(),m:x.getMinutes(),s:x.getSeconds()};
y = y.replace(/(M+|d+|h+|m+|s+)/g,function(v) {return ((v.length>1?"0":"")+eval('z.'+v.slice(-1))).slice(-2)});
return y.replace(/(y+)/g,function(v) {return x.getFullYear().toString().slice(-v.length)});
}
alert(date2str(new Date(),"yyyy-MM-dd hh:mm:ss"));
alert(date2str(new Date(),"yyyy-M-d h:m:s"));
</script>
</body>
</html><br /><center>如不能显示效果,请按Ctrl+F5刷新本页,更多网页代码:<a href='http://www.veryhuo.com/' target='_blank'>http://www.veryhuo.com/</a></center>
文章源自:烈火网,原文:http://www.veryhuo.com/a/view/38913.html
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics