JS 时间格式化函数
//时间格式化函数
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1, //month
"d+": this.getDate(), //day
"h+": this.getHours(), //hour
"m+": this.getMinutes(), //minute
"s+": this.getSeconds(), //second
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
"S": this.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,(this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o) if (new RegExp("(" + k + ")").test(format))format = format.replace(RegExp.$1,RegExp.$1.length == 1 ? o[k] :("00" + o[k]).substr(("" + o[k]).length));
return format;
}
使用方法: 1
new Date(blog.AddTime).format('yyyy-MM-dd hh-mm-ss');
//时间格式化函数
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1, //month
"d+": this.getDate(), //day
"h+": this.getHours(), //hour
"m+": this.getMinutes(), //minute
"s+": this.getSeconds(), //second
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
"S": this.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,(this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o) if (new RegExp("(" + k + ")").test(format))format = format.replace(RegExp.$1,RegExp.$1.length == 1 ? o[k] :("00" + o[k]).substr(("" + o[k]).length));
return format;
} //展现列表数据
function addTableRow(productionObj) {
var fields = ["get('title')","get('content')","createdAt.format('yyyy-MM-dd hh:mm:ss')"];
原文地址:http://www.cnblogs.com/henw/archive/2011/10/17/2215545.html
JS 时间格式化函数的更多相关文章
- js时间格式化函数,支持Unix时间戳
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- js时间格式化函数(兼容IOS)
* 时间格式化 * @param {Object} dateObj 时间对象 * @param {String} fmt 格式化字符串 */ dateFormat(dateObj, fmt) { le ...
- JS时间格式化函数
Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, //month & ...
- js 日期格式化函数(可自定义)
js 日期格式化函数 DateFormat var DateFormat = function (datetime, formatStr) { var dat = datetime; var str ...
- mysql时间格式化函数日期格式h和H区别
本文为博主原创,未经允许不得转载: 今天碰到一个问题,发现项目中有一个统计图的数据和时间格式没有对应准确,统计图要描述的是操作次数和操作时间的关系, 但很奇怪的是操作次数对应的时间却是凌晨,实际应用中 ...
- js 时间格式化 (兼容safari)
js 时间格式化,兼容IE8和safari浏览器. function formatDate(date, fmt, near, type) { var dateStr = date; if (!date ...
- JavaScript日期时间格式化函数
这篇文章主要介绍了JavaScript日期时间格式化函数分享,需要的朋友可以参考下 这个函数经常用到,分享给大家. 函数代码: //格式化参数说明: //y:年,M:月,d:日,h:时,m分,s:秒, ...
- SQL 时间格式化函数发布
SQL 时间格式化函数,有时候因某种需要需要格式化成需要的时间格式,需要的朋友可以收藏下,以备后用. SQL Server里面可能经常会用到的日期格式转换方法: sql server使用convert ...
- 时间戳显示为多少分钟前,多少天前的JS处理,JS时间格式化,时间戳的转换
var dateDiff = function (timestamp) { // 补全为13位 var arrTimestamp = (timestamp + '').split(''); for ( ...
随机推荐
- unicode转中文
<pre name="code" class="html">[root@dr-mysql01 ~]# cat a1.pl my $str=" ...
- WIN7下制作的ubunbu U盘安装无法使用
想在电脑上装个ubuntu 12.04来个双系统.就在win7下用U盘制作了个安装程序.但是U盘启动安装后一直无法开始安装.网上找了大半天才有个结论解决了. 步骤如下: 去ubuntu官网下载安装的i ...
- WordPress NOSpam PTI插件‘comment_post_ID’参数SQL注入漏洞
漏洞名称: WordPress NOSpam PTI插件‘comment_post_ID’参数SQL注入漏洞 CNNVD编号: CNNVD-201309-388 发布时间: 2013-09-24 更新 ...
- HDU-1495 非常可乐(BFS)
广搜的灵活应用题: 非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Qt学习之路(1)------Qt常用类用法说明
Qt常用类 向控制台输出文本 第一个例子,我们采用STL的方式: console.cpp #include <iostream> int main() { std::cout <&l ...
- Android线程计时器实现
cocos2dx的计时器很好用,但当app进入后台,其计时器会pause掉,如果想要一个稳恒计时器就得自己去实现完成了,在Cocos2d-x for ios中我们可以利用NSTimer类并结合objc ...
- Web---Cookie技术(显示用户上次登录的时间、显示用户最近浏览的若干个图片(按比例缩放))
本章博客讲解: 1.Cookie基本用法演示 2.演示Cookie的访问权限 3.演示Cookie的删除 4.利用Cookie显示用户上次登录的时间 5.利用Cookie技术显示用户最近浏览的若干个图 ...
- Problem 2214 Knapsack problem 福建第六届省赛
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2214 题目大意:给你T组数据,每组有n个物品,一个背包容量B,每件有体积和价值.问你这个背包容纳的物品最大价值 ...
- C++11的资源管理:泛化的RAII
RAII被认为是c++资源管理的最佳范式,但是c++98中用RAII必须为要管理的资源写一个类,这样一来RAII的使用就有些繁琐了.C++11有了lambda和function后,我们就可以编写泛化的 ...
- 开发小技巧:C#逐个输出字符
静态自定义方法: static int counter = 0; static string displayString = "This string will appear one let ...