js时间格式化
/**
* 日期时间格式化 (CST 转化为标准时间可用)
*/
exports.formatDateCst = function(stamp, formatString){
var date = new Date(stamp);
var o = {
'M+': date.getMonth() + 1,
'D+': date.getDate(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds(),
'S' : date.getMilliseconds()
};
if(/(Y+)/.test(formatString)){
formatString = formatString.replace(RegExp.$1, (date.getFullYear() + "").substr(2 - RegExp.$1.length));
}
for(var k in o){
if(new RegExp('(' + k + ')').test(formatString)){
formatString = formatString.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));
}
}
return formatString;
}
use: formatDateCst(value,'YY-MM-DD hh:mm:ss')
js时间格式化的更多相关文章
- js 时间格式化 (兼容safari)
js 时间格式化,兼容IE8和safari浏览器. function formatDate(date, fmt, near, type) { var dateStr = date; if (!date ...
- js时间格式化函数,支持Unix时间戳
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 时间戳显示为多少分钟前,多少天前的JS处理,JS时间格式化,时间戳的转换
var dateDiff = function (timestamp) { // 补全为13位 var arrTimestamp = (timestamp + '').split(''); for ( ...
- 表单序列化json字符串和js时间格式化
js时间格式化 new Date().format("时间格式") Date.prototype.format = function(fmt) { var o = { ...
- js时间格式化(yy年MM月dd日 hh:mm)
//时间格式化 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, / ...
- js 时间格式化 -- 时间加减实现
时间格式化的方法: Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.ge ...
- JS 时间格式化函数
//时间格式化函数 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, ...
- js时间格式化函数(兼容IOS)
* 时间格式化 * @param {Object} dateObj 时间对象 * @param {String} fmt 格式化字符串 */ dateFormat(dateObj, fmt) { le ...
- moment.js时间格式化库
网址:momentjs.cn 主要用来操作时间的格式化.通过发送API请求获取到的数据中:例如[新闻]中的 发布时间,有的时候.请求到的时间,后台没处理过,那么只能前端来操作数据了. moment.j ...
随机推荐
- Asp.net中导出Excel文档(Gridview)
主要思路,通过GridView来导出文档. 新建一个Aspx页面,页面创建GridView控件,后台绑定好数据源.然后load中直接打印即可导出 前台的GridView <asp:GridVie ...
- UVA 12544 - Beehives O(nm) 无向图最小环
Bees are one of the most industrious insects. Since they collect nectarand pollen from flowers, they ...
- .NET Oracle Developer的福音——ODP.NET Managed正式推出
在.NET平台下开发Oracle应用的小伙伴们肯定都知道一方面做Oracle开发和实施相比SqlServer要安装Oracle客户端(XCopy.自己提取相关文件也有一定复杂性),另一方面相比JAVA ...
- mysql解压版安装
1.下载MySQL解压版(32位) http://dev.mysql.com/downloads/mysql/
- Unity Standard Assets 简介之 CrossPlatformInput
这篇介绍跨平台输入工具包CrossPlatformInput,主要包括 Prefabs 和 Scripts 两个文件夹: 由于该包中的脚本联系比较紧密,都是配合着去实现特定的功能,没有太大的独立可重用 ...
- js 字符串中的\n不会换行
var str1=aaaaaaa\nbbbbbbb; alert(str1); //不换行 ???不知所以然 解决办法: while (str1.indexOf("\\n") & ...
- 对于amqplib的使用心得
最近在nodejs使用了amqplib--rabbitmq的nodejs客户端.封装在了express中,先来代码. var amqp = require('amqplib/callback_api' ...
- How does Unity.Resolve know which constructor to use?
Question: Given a class with several constructors - how can I tell Resolve which constructor to use? ...
- java分享第十天(http协议简介)
URL模式URL(Uniform Resource Locator) 地址用于描述一个网络上的资源, 基本格式如下scheme 指定低层使用的协议(例如:http, https, ftp)host H ...
- DAO 开发模式的几个类
1, vo --> Emp.java 包括getter setter方法 2, dbc --> DatabaseConnection.java 数据库打开关闭 3, ...