700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > gmt时间转换格式 js_「js格式化」JS时间格式化 时间戳的转换 - seo实验室

gmt时间转换格式 js_「js格式化」JS时间格式化 时间戳的转换 - seo实验室

时间:2021-02-16 18:29:59

相关推荐

gmt时间转换格式 js_「js格式化」JS时间格式化 时间戳的转换 - seo实验室

js格式化

JS 时间格式化为yyyy-MM-dd hh:mm:ss

例:将Thu Sep 20 16:23:03 GMT+0800 (中国标准时间)转换为"-09-20 16:23:03"

方法一:function formatDateTime(inputTime) {

var date = new Date(inputTime);

var y = date.getFullYear();

var m = date.getmonth() + 1;

m = m < 10 ? ('0' + m) : m;

var d = date.getDate();

d = d < 10 ? ('0' + d) : d;

var h = date.getHours();

h = h < 10 ? ('0' + h) : h;

var minute = date.getMinutes();

var second = date.getSeconds();

minute = minute < 10 ? ('0' + minute) : minute;

second = second < 10 ? ('0' + second) : second;

return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;

};

调用该方法:console.log(formatDateTime(new Date()));

方法二: 针对date原型加Format()方法。// 对Date的扩展,将 Date 转化为指定格式的String

// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,

// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)

// 例子:

// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> -07-02 08:09:04.423

// (new Date()).Format("yyyy-M-d h:m:s.S") ==> -7-2 8:9:4.18

Date.prototype.Format = function(fmt)

{ //author: meizz

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;

}

调用该方法:console.log(new Date().Format("yyyy-MM-dd hh:mm:ss"))

时间转时间戳

将Thu Sep 20 16:47:52 GMT+0800 (中国标准时间)转换为1537433272051console.log(Date.parse(new Date()))

console.log(new Date().getTime())

将"-09-20 16:50:48"转换为1537433448000var timeDate = "-09-20 16:50:48";

var Time = new Date(timeDate);

var timestemp = Time.getTime();

console.log(timestemp)

相关阅读

在开发中美工进行标注都是十六进制的颜色值,很少直接写具体的颜色值,有时出现的具体的颜色值也是已经规定好的十六进制的颜色值;十六

H.264 是MPEG-4 标准所定义的最新格式,同时也是技术含量最高、代表最新技术水平的视频编码格式之一,有的也称(AVC)。

使用软件MediaCo

http://vectormagic.stanford.edu/

这篇文章请允许我啰嗦几句,讲一下前因后果。起因:

1.查看生产日志(巨大:大都是一两个GB),使用普通编辑器打开巨慢无比2.手写java工具类,

一、引用转载1:/jmliao/p/5594179.html转载2:/xiaoxiaoyusheng/article/details/4

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。