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 ...
随机推荐
- hdu2196 树形dp
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2196 Problem Description A school bought the fi ...
- Leetcode Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- 简明 Git 命令速查表(中文版)
原文引用地址:https://github.com/flyhigher139/Git-Cheat-Sheet/blob/master/Git%20Cheat%20Sheet-Zh.md在Github上 ...
- 02.JavaScript基础下
运算符 算术:+ 加.- 减.* 乘./ 除.% 取模 实例:隔行变色.秒转时间 赋值:=.+=.-=.*=./=.%= 关系:<.>.<=.>=.==.===.!=(不等). ...
- 20145205 实验一 Java开发环境的熟悉
实验内容 命令行下Java程序开发 IDEA下Java程序开发.调试 练习(通过命令行和Eclipse两种方式实现,在Eclipse下练习调试程序) 实现凯撒密码,并进行测试 实验要求 使用JDK编译 ...
- php如何查看变量是真实被引用
$var1 = 'Hello World'; $var2 = ''; $var2 =&$var1; debug_zval_dump(&$var1); $a = "aaa&qu ...
- 浏览器IE与非IE区分
1. window.VBArray IE自带 if(window.VBArray) {console.log("IE 浏览器");} else{console.log(" ...
- 学习Http协议和当下主流的Rx+Retrofit的主流框架
所有的劳累都会烟消云散了.不只在生活上,也对我的心态上发生了翻天覆地的变化.在和她在一起之前,我总觉得自己很小,不会去站在别人的角度替别人思考问题,没事就乱发脾气,抑或是一直沉迷于游戏.而和她在一起后 ...
- Tomcat(多版本)安装注意!
♣电脑安装多个版本的tomcat和切换(解压版的apache-tomcat -5.5.0/ -6.0.45/ -7.0.70 三个版本) ♣tomcat配置环境变量 ♣tomcat5.5. ...
- MyBatis快速入门
一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以 ...