js得到规范的时间格式函数,并调用

1.js得到规范的时间格式函数

Date.prototype.format = function(fmt) {

var o = {

"M+" : this.getMonth()+1,                 //月份

"d+" : this.getDate(),                    //日

"h+" : this.getHours(),                   //小时

"m+" : this.getMinutes(),                 //分

"s+" : this.getSeconds(),                 //秒

"q+" : Math.floor((this.getMonth()+3)/3), //季度

"S"  : this.getMilliseconds()             //毫秒

};

if(/(y+)/.test(fmt)) {

fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));

}

for(var k in o) {

if(new RegExp("("+ k +")").test(fmt)){

fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));

}

}

return fmt;

}

2.调用时间函数

nowdate=now.format("yyyy-MM-dd hh:mm:ss");

原文地址:https://www.cnblogs.com/TiantianLi/p/10262500.html

时间: 2024-08-29 03:15:57

js得到规范的时间格式函数,并调用的相关文章

js 时间戳转换成时间格式,可自定义格式

由于 c# 通过ajax获取的时间 传到前台 格式为:/Date(1354116249000)/ 所以需要转换一下,想要什么格式 更改 format() 里的 返回语句 就可以了 formatDate()方法传入的参数是时间戳,可以用replace()得到时间戳:replace("/Date(", "").replace(")/", ""),然后传入方法,就可以得到时间格式了 function formatDate(obj)

JS 时间戳转化为时间格式

function getLocalTime(nS) { return new Date(parseInt(nS)).toLocaleString().replace(/:\d{1,2}$/, ' ').replace("年", '-').replace("月", '-').replace("日", '').substring(0, 10); } 转化出来的时间格式为  yyyy-MM-dd

js将时间戳转为时间格式

时间戳转时间格式 //分钟 let timeM= parseInt(msg/1000/60%60); if(timeM<10){ timeM="0"+timeM; } //秒钟 let timeS=parseInt(msg/1000%60); if(timeS<10){ timeS="0"+timeS; } let time=timeM+":"+timeS; 原文地址:https://www.cnblogs.com/qq3763247

postgresql数据库中判断是否是数字和日期时间格式函数

/* 在编写GreenPlum函数的过程中,遇到要判断字符串是否是数字和日期格式的情况,基于GreenPlum和postgresql的亲缘关系,找到了下面两个函数. */ --1.判断字符串是否是数字 CREATE OR REPLACE FUNCTION isnumeric(txtStr VARCHAR) RETURNS BOOLEAN AS $$ BEGIN RETURN txtStr ~ '^([0-9]+[.]?[0-9]*|[.][0-9]+)$'; END; $$ LANGUAGE '

js、jquery验证时间格式

下面验证的格式是2012-2-1 或2010-02-01 var reDate = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(

js 显示友好的时间格式【刚刚、几秒前,几小时,几天前(3天内) 时间格式化】

/** * 毫秒转换友好的显示格式 * 输出格式:21小时28分钟15秒 * @param {[type]} time [description] * @return {[type]} [description] */ function timeToDate(time) { // 获取当前时间戳 var currentTime = parseInt(new Date().getTime()/1000); var diffTime = currentTime-time; var second =

js 显示友好的时间格式【刚刚、几分钟前、几小时、几天前、几周前、几月前等等 时间格式化】(工具类)

/** * 毫秒转换友好的显示格式 * 输出格式:21小时前 * stringTime为:年-月-日 时:分:秒 * @param {[type]} time [description] * @return {[type]} [description] */function friendlyFormatTime(stringTime) { let minute = 1000 * 60; let hour = minute * 60; let day = hour * 24; let week =

mysql中返回当前时间的函数或者常量

引用:http://blog.sina.com.cn/s/blog_6d39dc6f0100m7eo.html 1.1 获得当前日期+时间(date + time)函数:now() 除了 now() 函数能获得当前的日期时间外,MySQL 中还有下面的函数: current_timestamp()   current_timestamp localtime()   localtime localtimestamp()   localtimestamp     这些日期时间函数,都等同于 now(

mysql中时间日期函数

转自:mysql 中 时间和日期函数 一.MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间(date + time)函数:now() mysql> select now(); +---------------------+| now()               |+---------------------+| 2008-08-08 22:20:46 |+---------------------+ 除了 now() 函数能获得当前的日期时间外,MySQL 中还有下面的函数: