js,格式化long类型日期封装
2024-10-19 00:24:37
/**
* 扩展date函数
* author:c3gen
*/ Date.prototype.format = function(format) {
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(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;
} /**
date 为long类型
pattern 为格式化参数
*/
function getFormatDate(date, pattern) {
if (date == undefined) {
date = new Date();
}
if (pattern == undefined) {
pattern = "yyyy-MM-dd hh:mm:ss";
}
return date.format(pattern);
} $(function() {
var s = new Date(1388776825);
alert(s);
alert(getFormatDate(s));
})
最新文章
- 浅析call和apply
- LruCache详解之 Android 内存优化
- Android APK反编译就这么简单 详解(附图)
- javaweb学习总结(九)—— 通过Servlet生成验证码图片
- BZOJ-1901 Zju2112 Dynamic Rankings 函数式线段树 套 树状数组+离线处理
- Android控件大全(三)——RecyclerView
- HttpRuntime.Cache被清空的DataTable
- IIS配置及防黑
- java MYSQL做分页
- ABAP ALV DEMO示例源码
- bzoj1662: [Usaco2006 Nov]Round Numbers 圆环数
- Python中使用Flask、MongoDB搭建简易图片服务器
- KNN算法理解
- dev repositoryItem 手工定义
- tomcat启动不了,内存溢出
- 关于无法下载android开发工具的解决方法
- fgrep: ifcfg-ifcfg-eth0: No such file or directory
- python hex() oct() bin() math 内置函数
- ionic 页面传递参数
- codeforces round#510