Date.prototype.format,js下的时间格式处理函数
该方法在date的原型中扩展了format方法,使其可以方便的格式化日期格式输出。
Date.prototype.format =function(format)
{
var o = {
"M+" : this.getMonth()+, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+)/), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format)) format=format.replace(RegExp.$,
(this.getFullYear()+"").substr(- RegExp.$.length));
for(var k in o)if(new RegExp("("+ k +")").test(format))
format = format.replace(RegExp.$,
RegExp.$.length==? o[k] :
(""+ o[k]).substr((""+ o[k]).length));
return format;
}
var date = new Date(parseInt(""));
date.format("yyyy-MM-dd");
只是项目中看到,有时间在研究下原理和参数。
Date.prototype.format,js下的时间格式处理函数的更多相关文章
- js处理数据库时间格式/Date(1332919782070)/
js处理数据库时间格式 数据库返回时间格式:/Date(1332919782070)/ 方法: function ChangeDateFormat(val) { if (val != null) { ...
- js 获取当前日期时间 格式为 yyyy-mm-dd hh:MM:ss
------------------------------------------------------------------------------------ js 获取当前日期时间 格式为 ...
- Date.prototype.format
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- 扩展Date的format方法--格式化日期时间
Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, "d+& ...
- [php基础]Mysql日期函数:日期时间格式转换函数详解
在PHP网站开发中,Mysql数据库设计中日期时间字段必不可少,由于Mysql日期函数输出的日期格式与PHP日期函数之间的日期格式兼容性不够,这就需要根据网站实际情况使用Mysql或PHP日期转换函数 ...
- MySQL时间戳和时间格式转换函数
MySQL时间戳和时间格式转换函数:unix_timestamp and from_unixtime unix_timestamp将时间转化成时间戳格式.from_unixtime将时间戳转化成时间格 ...
- 使用饿了么el-date-picker里及如何将后台给的时间戳js转化为时间格式
首先代码是这个样子的,使用v-model <el-date-picker v-model="formData.createTime" :disabled="true ...
- JS时间戳转时间格式
//转化为时间格式 function getDate(timestamp) { timestamp = timestamp.replace("/Date(", "&quo ...
- js时间戳和时间格式之间的转换
//时间戳转换成日期时间2014-8-8 下午11:40:20 function formatDate(ns){ return new Date(parseInt(ns) * 1000).toLoca ...
随机推荐
- 【转】Javabyte[]数组和十六进制String之间的转换Util------包含案例和代码
原文网址:http://blog.csdn.net/caijunjun1006/article/details/11740223 Java中byte用二进制表示占用8位,而我们知道16进制的每个字符需 ...
- 数位DP:SPOJ KPSUM - The Sum
KPSUM - The Sum One of your friends wrote numbers 1, 2, 3, ..., N on the sheet of paper. After that ...
- interview material
Articles Recommended: Steve Yegge – Get That Job at Google [web] Carlos Bueno – Get That Job at Face ...
- 滑雪 (搜索)(dp)(贪心)
以每一点为起点找出所有路径,并求出以此点做为起点的最大路径 求出每个点的最大路径后再找出其中最大的值,输出最大值 #include <stdio.h>#include <string ...
- [Javascript] Promise
Promise 代表着一个异步操作,这个异步操作现在尚未完成,但在将来某刻会被完成. Promise 有三种状态 pending : 初始的状态,尚未知道结果 fulfilled : 代表操作成功 r ...
- poj3258
题目翻译 二分法(其实两个单词的意思分别是河,跳格子游戏,至于为啥翻译成二分法- -只能说英语博大精深啊) 奶牛每年举办一场有特色的跳格子游戏(很明显题目翻译错误)涉及到在河里从一块岩石跳到另一块岩石 ...
- Spring 配置中的 default-lazy-init属性
spring的容器是提供了lazy-load的,即默认的缺省设置是bean没有lazy-load,该属性处于false状态,这样导致spring在启动过程导致在启动时候,会默认加载整个对象实例图,从初 ...
- Redis sort命令
http://www.cnblogs.com/linjiqin/archive/2013/06/14/3135921.html 1.添加 投票选项到 redis的 List 和HashMap lis ...
- KVM与VMware的性能比较
结合网页http://www.linuxidc.com/Linux/2011-01/31755.htm等整理 物理环境内存4G ,CPU4个,动态硬盘120G KVM: 硬盘测试瞬间读取速度Timin ...
- iOS开发系列之触摸事件
基础知识 三类事件中触摸事件在iOS中是最常用的事件,这里我们首先介绍触摸事件. 在下面的例子中定义一个KCImage,它继承于UIView,在KCImage中指定一个图片作为背景.定义一个视图控制器 ...