javascript Date format(js日期格式化)
2012-09-03 20:24
351 查看
最近在给中国证券网做网站改版的时候碰到这么一个问题, 在各个地方时间的显示格式都不一样, 各有各的风格, 有的地方要用
yyyy-MM-dd 格式的, 有的地方又要用 HH:mm:ss 格式的, 而有的地方又要用 yy-MM-dd HH:mm 格式的, 而后台往 XML 文件中写入的时候统一都是写的 yyyy-MM-dd HH:mm:ss.SSS 格式的, 于是在网上搜索了一下"js date format", 搜索出来的结果是大把大把的, 于是乎一个一个网页的打开瞧瞧, 最后终于被我找着了两个既好用,代码又易懂的, 现在贴出来给大家参考参考。
下面是第一个, 来源:http://blog.csdn.net/yuyue618/archive/2009/04/15/4074793.aspx
view plaincopy to clipboardprint?
<script language="javascript" type="text/javascript">
<!--
Date.prototype.pattern=function(fmt) {
var o = {
"M+" : this.getMonth()+1, //月份
"d+" : this.getDate(), //日
"h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时
"H+" : this.getHours(), //小时
"m+" : this.getMinutes(), //分
"s+" : this.getSeconds(), //秒
"q+" : Math.floor((this.getMonth()+3)/3), //季度
"S" : this.getMilliseconds() //毫秒
};
var week = {
"0" : "\u65e5",
"1" : "\u4e00",
"2" : "\u4e8c",
"3" : "\u4e09",
"4" : "\u56db",
"5" : "\u4e94",
"6" : "\u516d"
};
if(/(y+)/.test(fmt)){
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
yyyy-MM-dd 格式的, 有的地方又要用 HH:mm:ss 格式的, 而有的地方又要用 yy-MM-dd HH:mm 格式的, 而后台往 XML 文件中写入的时候统一都是写的 yyyy-MM-dd HH:mm:ss.SSS 格式的, 于是在网上搜索了一下"js date format", 搜索出来的结果是大把大把的, 于是乎一个一个网页的打开瞧瞧, 最后终于被我找着了两个既好用,代码又易懂的, 现在贴出来给大家参考参考。
下面是第一个, 来源:http://blog.csdn.net/yuyue618/archive/2009/04/15/4074793.aspx
view plaincopy to clipboardprint?
<script language="javascript" type="text/javascript">
<!--
Date.prototype.pattern=function(fmt) {
var o = {
"M+" : this.getMonth()+1, //月份
"d+" : this.getDate(), //日
"h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时
"H+" : this.getHours(), //小时
"m+" : this.getMinutes(), //分
"s+" : this.getSeconds(), //秒
"q+" : Math.floor((this.getMonth()+3)/3), //季度
"S" : this.getMilliseconds() //毫秒
};
var week = {
"0" : "\u65e5",
"1" : "\u4e00",
"2" : "\u4e8c",
"3" : "\u4e09",
"4" : "\u56db",
"5" : "\u4e94",
"6" : "\u516d"
};
if(/(y+)/.test(fmt)){
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
相关文章推荐
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- (转)javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化) (转)
- javascript中Date format(js日期格式化)方法小结
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)
- javascript Date format(js日期格式化)