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 ...
随机推荐
- IIS7授权错误:“无法验证对路径的访问”的解决方法
解决方法: iis7 无法验证对路径的访问 1.打开IIS 7管理器,鼠标单击定位到出现了这个错误的网站. 2.在IIS 7管理器的右边,选择“基本设置”. 3.在弹出的“编辑网站”对话框中,单击“连 ...
- 【索引】Android相关的
Eclipse开发环境 JDK的下载和安装:http://www.cnblogs.com/duxiuxing/p/4771901.html Android SDK的下载和安装:http://www.c ...
- POJ2286 The Rotation Game(IDA*)
The Rotation Game Time Limit: 15000MS Memory Limit: 150000K Total Submissions: 5691 Accepted: 19 ...
- [Theano] Theano初探
1. Theano用来干嘛的? Theano was written at the LISA lab to support rapid development of efficient machine ...
- 《A First Course in Mathematical Modeling》-chaper1-差分方程建模
从今天开始笔者将通过这个专栏可是对“数学建模”的学习.其实对于“数学建模”自身的内涵或者意义并不需要太多的阐释,下图简洁明了的阐释了数学建模的意义. 其实数学建模本身可以看成换一种角度去解读数学,将我 ...
- HDU1510 White rectangles
White Rectangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- PHP 生命周期,Opcode 缓存。
1.php 执行的生命周期. 用户发出请求---->.php--->词典扫描--->解析--->创建Opcode--->处理opcode--->响应 这就是php的 ...
- HTML的简单介绍
<html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="Co ...
- opentesty--luasocket 安装
转载请注明原文地址:http://www.cnblogs.com/dongxiao-yang/p/4878323.html luasocket安装过程中遇到不少坑,之前采用的是从公司以前服务器的里面找 ...
- dubbo源码分析一:整体分析
本文作为dubbo源码分析的第一章,先从总体上来分析一下dubbo的代码架构.功能及优缺点,注意,本文只分析说明开源版本提供的代码及功能. 1.dubbo的代码架构: spring适配层:常规的sp ...