码迷,mamicode.com
首页 > Web开发 > 详细

js获取日期

时间:2017-07-30 10:06:20      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:js

js获取日期:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<div><span id="test">2017654165</span></div>
</body>
<script type="text/javascript" src="https://www.qianduanzhan.com/jquery/3.2.1/jquery.min.js"></script>
<script>
   
    (function($){
	var Formatter = function(opt,obj){
		var date = new Date(),
		yy = date.getFullYear(),
		MM = date.getMonth()+1,
		DD = date.getDate(),
		H = date.getHours(),
		M = date.getMinutes(),
		S = date.getSeconds(),
		fmtdate = opt.fmt.replace(‘yyyy‘,yy)
		             .replace(‘mm‘,MM)
		             .replace(‘dd‘,DD)
		             .replace(‘h‘,H)
		             .replace(‘m‘,M)
		             .replace(‘s‘,S);
		obj.text(fmtdate);

	}
	$.fn.formatter = function(opt){
		return new Formatter(opt,this)
	}
})(jQuery);
    $("#test").formatter({fmt:‘yyyy-mm-dd h:m:s‘}); 
</script>
</html>


js获取日期

标签:js

原文地址:http://13136447.blog.51cto.com/13126447/1951995

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!