js Date 时间格式化的扩展
js Date 时间格式化的扩展:
Date.prototype.format = function (fmt) {
var o = {
"M+": this.getMonth() + , //月
"d+": this.getDate(), //日
"h+": this.getHours() % == ? : this.getHours() % , //时
"H+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + ) / ), //季
"S": this.getMilliseconds() //毫秒
};
var week = {
"": "\u65e5",
"": "\u4e00",
"": "\u4e8c",
"": "\u4e09",
"": "\u56db",
"": "\u4e94",
"": "\u516d"
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$, (this.getFullYear() + "").substr( - RegExp.$.length));
}
if (/(E+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$, ((RegExp.$.length > ) ? (RegExp.$.length > ? "\u661f\u671f" : "\u5468") : "") + week[this.getDay() + ""]);
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$, (RegExp.$.length == ) ? (o[k]) : (("" + o[k]).substr(("" + o[k]).length)));
}
}
return fmt;
}
使用方法如下:
var date = new Date("2016-03-11T16:20:12");
$("#divResult").html(date.format("yyyy-MM-dd EE HH:mm:ss"));
js Date 时间格式化的扩展的更多相关文章
- JS Date 时间格式化
Date2Str(x, y) { , d: x.getDate(), h: x.getHours(), m: x.getMinutes(), s: x.getSeconds() }; y = y.re ...
- js -- 日期时间格式化
/** * js日期时间格式化 * @param date 时间读对象 * @param format 格式化字符串 例如:yyyy年MM月dd日 hh时mm分ss秒 * @returns {stri ...
- date时间格式化
Date方法的扩展 /** * 时间格式化 * @param fmt * @returns {*} * @constructor */ // (new Date()).Format("yyy ...
- js 中时间格式化的几种方法
1.项目中时间返回值,很过时候为毫秒值,我们需要转换成 能够看懂的时间的格式: 例如: yyyy-MM-dd HH:mm:ss 2.处理方法(处理方法有多种,可以传值到前端处理,也可以后台可以好之后再 ...
- js Date 日期格式化(转)
var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年份(4位,1 ...
- JS 自定义时间格式化
// 对Date的扩展,将 Date 转化为指定格式的String// 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位 ...
- 关于JS Date 时间计算
倒计时功能Demo:http://play.163.com/special/test-timeending/?1465197963677 获取时间 Date() 返回当日的日期和时间. getDate ...
- js Date日期对象的扩展
// 对Date的扩展,将 Date 转化为指定格式的String// 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位 ...
- 用JavaScript(js)对时间格式化
Date.prototype.format =function(format) { var o = { "M+" : (this.getMo ...
随机推荐
- RHCE 系列(九):如何使用无客户端配置 Postfix
转载于:http://www.itxuexiwang.com/a/liunxjishu/2016/0220/152.html?1456382561 尽管现在有很多在线联系方式,电子邮件仍然是一个人传递 ...
- Redis的使用模式之计数器模式实例
转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/123.html?1455853785 Redis 是目前 NoSQL 领域 ...
- Atitit 图像扫描器---基于扫描线
Atitit 图像扫描器---基于扫描线 调用范例 * @throws FileExistEx */ public static void main(String[] args) throws Fil ...
- javascript_core_07之错误处理、函数作用域
1.错误处理:保证程序发生错误时,不会被强制退出: ①处理方式:try{可能出错的正常语句:}catch(err){只有出现错误时才执行的错误处理代码:}finally{无论是否出错都必须执行的代码: ...
- webpack配置详解
webpack配置详解 先点个赞吧,再挨个点下面的连接,觉得不值这个赞的回来骂我啊. Webpack傻瓜式指南(一) Webpack傻瓜指南(二)开发和部署技巧 Webpack傻瓜式指南 原生的官网详 ...
- 关于sass的介绍和基本语法
引入 什么是sass?sass是css预处理器. 那预处理器又是什么?css本身不是一种编程语言,而预处理器是用一种专门的编程语言,进行网页样式设计,然后再编译成正常的CSS文件. 如今主流的预处理器 ...
- ELCImagePickerController 的集成
1, 将文件夹ELCImagePicker拷贝到工程中 2,添加系统库AssetsLibrary.framework 3, 添加系统库MobileCoreServices 4,在头文件中加入引用# ...
- Python小爬虫实例
有几个注意点: # -*- coding: utf-8 -*- # func passport jw.qdu.edu.cn import re import urllib# python3后urlli ...
- 最简单的可取消多选效果(以从水果篮中挑选水果为例)【jsDEMO】
[功能说明] 最简单的可取消多选效果(以从水果篮中挑选水果为例) [html代码说明] <div class="box" id="box"> < ...
- Unity3D协同程序(Coroutine)
摘要下: 1. coroutine, 中文翻译"协程".这个概念可能有点冷门,不过百度之,说是一种很古老的编程模型了,以前的操作系统里进程调度里用到过,现在操作系统的进程调度都是根 ...