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 ...
随机推荐
- [转]stringstream的用法
使用stringstream对象简化类型转换C++标准库中的<sstream>提供了比ANSI C的<stdio.h>更高级的一些功能,即单纯性.类型安全和可扩展性.在本文中, ...
- 衬衫面料品牌:Alumo_衬衫_男装_男装:衬衫、法式衬衫、袖扣领带、西服西裤等男士正装服饰-仕族官网
衬衫面料品牌:Alumo_衬衫_男装_男装:衬衫.法式衬衫.袖扣领带.西服西裤等男士正装服饰-仕族官网 衬衫面料品牌:Alumo
- 阿里巴巴算法工程师四面(三轮技术+hr面)详细面经
阿里面试总结: 一遍一遍地刷阿里网站,今天发现“面试中”变成“待跟进offer”了,写个面经攒人品,希望offer通知邮件早点来吧. 我当时投简历时投了C/C++工程师,其实也没经过啥考虑,因为我一开 ...
- Linux 安全
Linux 安全 1.安装 使系统处于单独(或隔离)的网络中.以防止未受保护的系统连接到其它网络或互联网中受到可能的攻击 安装完成后将下面软件卸载 pump ...
- c# mongo 返回指定的列
var query= db.GetCollection<Merchant>("merchant").Find(Query<Merchant>.EQ(m =& ...
- CreateThread函数
当使用CreateProcess调用时,系统将创建一个进程和一个主线程. CreateThread将在主线程的基础上创建一个新线程,大致做例如以下步骤: 1在内核对象中分配一个线程标识/句柄,可供管理 ...
- HDU1097 A hard puzzle
A hard puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- PHP 函数的“引用返回”概念释疑(转)
很多时候我们会看到这样的代码(出自 CI 框架源码): 1 $class =& load_class('a','b'); 我们都知道其中的'&'是指引用,但是它的作用是什么呢?它能够解 ...
- Where Jboss7.1 take war application to deploy--reference
Question i've deployed the jboss-as-helloworld-errai application in my standalone jboss7.1 instance, ...
- mysql 大表 Sharding [转]
参看以下两篇文章 http://www.dedecms.com/knowledge/data-base/mysql/2012/0820/9172.html http://dbanotes.net/da ...