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 ...
随机推荐
- jQuery疑惑记录
不断更新 1.项目中有一句 this.$html = $('<div/>').html(html).attr('sspa-mod-id', this.modName).hide();不知道 ...
- Java中equals与==和comparaTo的区别
一.先说说Java中equals和==的区别: Java中的数据类型,可分为两类: 1.基本数据类型(也叫原始数据类型) 八大基本数据类型 char byte short int long doubl ...
- Linux内核TCP/IP参数分析与调优
转载于:http://www.itxuexiwang.com/a/liunxjishu/2016/0225/167.html?1456482565 如下图展示的是TCP的三个阶段.1,TCP三次握手. ...
- 转 jsp中 session的简单用法
Session对象:是用来分别保存每一个用户信息的对象,以便于跟踪用户的操作状态.Session的信息保存在服务端,Session的ID保存在客户机的Cookie中.事实上,在许多服务器上,如果浏览器 ...
- 搭建LNAMP环境(五)- PHP7源码安装Redis和Redis拓展
上一篇:搭建LNAMP环境(四)- 源码安装PHP7 一.安装Redis 1.创建redis用户组和用户 groupadd redis useradd -r -g redis -s /sbin/nol ...
- 18.实现如下类之间的继承关系,并编写Music类来测试这些类。
package zhongqiuzuoye; public class Instrument { public void play() { System.out.println("弹奏乐器& ...
- Python之函数与变量
本节内容 函数介绍及其作用 函数的定义与调用 函数的参数说明 全局变量与局部变量 值传递和引用传递 一.函数的介绍及其作用 编程语言中的函数与数学中的函数是有区别的:数学中的函数有参数(输入),就会有 ...
- Java 线程 — ThreadLocal
ThreadLocal 先来看看ThreadLocal的注释: This class provides** thread-local variables**. These variables diff ...
- ASPNET_WEBAPI快速学习02
这部分内容的学习,已经放了大半年时间了,果断补充上,尽早将过去遗留的老技术坑都补上.首先将介绍服务幂等性的概念和相关解决方案,这部分也将是本文的理解难点,由于WebAPI是一种Restful风格服务的 ...
- 移动端BUG汇总
position:fixed问题 固定定位到底部会把最后一个元素盖住 你会发现最后一个字被盖住了,并且还滚动不下去. 解决方法: 给后一个元素添加一个高度,或者给body加margin-bottom ...