81,122
社区成员




<div class="row">
<div class="col-md-12 center-block">
<h2 id="mine">暂时没有东西</h2>
<h3 id="time"></h3>
</div>
</div>
</div>
<script src="static/js/jquery-2.2.2.js"></script>
<script src="static/js/bootstrap.js"></script>
<script>
$(document).ready(function() {
$("#time").html(new Date())
})
</script>
我原来也是没乱码,而且我记得好像后面有一串中国标准时间这样的字样,但是现在这里就乱码了,不知道什么情况。难道是我的操作系统区域语言设置崩了?前段时间确实改过语言,难道是留下后遗症了 如果是这玩意的话,那就是正常的 Fri Apr 22 14:09:09 UTC+0800 2016
// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.format = function(fmt)
{ //author: meizz
var o = {
"M+" : this.getMonth()+1, //月份
"d+" : this.getDate(), //日
"H+" : this.getHours(), //小时
"m+" : this.getMinutes(), //分
"s+" : this.getSeconds(), //秒
"q+" : Math.floor((this.getMonth()+3)/3), //季度
"S" : this.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt))
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var k in o)
if(new RegExp("("+ k +")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
return fmt;
}
var d = new Date();
var timeStr= d.format("yyyy-MM-dd HH:mm:ss")
$("#time").text(timeStr);
你现在页面的编码格式是什么,
注意下: $("#time").html(new Date()) new Date() 出来的是一个date对象,不可以直接进行使用; 给你一个日期格式化扩展;加载以上的代码以后,可以调用// 对Date的扩展,将 Date 转化为指定格式的String // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) // 例子: // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 Date.prototype.format = function(fmt) { //author: meizz var o = { "M+" : this.getMonth()+1, //月份 "d+" : this.getDate(), //日 "H+" : this.getHours(), //小时 "m+" : this.getMinutes(), //分 "s+" : this.getSeconds(), //秒 "q+" : Math.floor((this.getMonth()+3)/3), //季度 "S" : this.getMilliseconds() //毫秒 }; if(/(y+)/.test(fmt)) fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); for(var k in o) if(new RegExp("("+ k +")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); return fmt; }
var d = new Date(); var timeStr= d.format("yyyy-MM-dd HH:mm:ss") $("#time").text(timeStr);
如果是这玩意的话,那就是正常的 Fri Apr 22 14:09:09 UTC+0800 2016
把你整个页面贴出来,看看到底是哪里的问题
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>date</title>
</head>
<body>
<h2><script>document.write(new Date())</script></h2>
<h2><script>document.write(new Date().toString())</script></h2>
<h2><script type="text/javascript">
document.write(new Date().toLocaleTimeString())
</script></h2>
</body>
</html>