JS 格林威治时间格式(GMT)格式化

Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1, //month
"d+": this.getDate(), //day
"h+": this.getHours(), //hour
"m+": this.getMinutes(), //minute
"s+": this.getSeconds(), //second
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
"S": this.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
(this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o) if (new RegExp("(" + k + ")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length == 1 ? o[k] :
("00" + o[k]).substr(("" + o[k]).length));
return format;
}

function DateTimeFormatter(value) {
if (value == undefined) {
return "";
}
/*json格式时间转js时间格式*/
value = value.substr(1, value.length - 2);
var obj = eval(‘(‘ + "{Date: new " + value + "}" + ‘)‘);
var dateValue = obj["Date"];
if (dateValue.getFullYear() < 1900) {
return "";
}
//return dateValue
return dateValue.format("yyyy-MM-dd hh:mm:ss");
}
时间: 2024-08-29 15:11:21

JS 格林威治时间格式(GMT)格式化的相关文章

格林威治时间格式(GMT)与普通时间格式的互相转换

GMT --> 普通时间格式: 方法: function GMTToStr(time){ var date = new Date(time) var Str=date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds() return Str } 调用: var to

js判断时间格式是否正确代码

js判断时间格式是否正确代码: 如果要求比较严格的话,时间格式也是需要进行判断的,下面就是一段这样的代码实例,希望能够给需要的朋友带来一定的帮助. 代码实例如下: function isDateString(strDate) { var strSeparator = "-"; var strDateArray; var intYear; var intMonth; var intDay; var boolLeapYear; var ErrorMsg = ""; st

Java之格林威治时间格式转换成北京时间格式

Java之格林威治时间格式转换成北京时间格式 package com.mtons.mblog; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class DateUtils { /** * 支持jdk1.6的写法<br/> * 解析2015-12-27T14:20:34+08:00格式类型的时

JS时间格式 GMT格式转换

JavaScript时间格式转换总结 1.当前系统区域设置格式(toLocaleDateString和toLocaleTimeString) 例子:(new Date()).toLocaleDateString() + " " + (new Date()).toLocaleTimeString()结果: 2008年1月29日 16:13:112.普通字符串(toDateString和toTimeString) 例子: (new Date()).toDateString() + &quo

29-jsp中用js进行时间格式转化

CST可以为如下4个不同的时区的缩写: 美国中部时间:Central Standard Time (USA) UT-6:00 澳大利亚中部时间:Central Standard Time (Australia) UT+9:30 中国标准时间:China Standard Time UT+8:00 古巴标准时间:Cuba Standard Time UT-4:00 GMT 世界时UT [1]  即格林尼治 [1]  平太阳时间,是指格林尼治所在地的标准时间,也是表示地球自转速率的一种形式 GMT指

js 不同时间格式介绍以及相互间的转换

首先必须要提到的是 Date 对象,它用来处理时间和日期. 使用 new Date() 语句可创建 Date 对象,创建出来的时间格式如下(后面提到的标准时间都是指该格式): Wed Jul 17 2019 13:59:21 GMT+0800 (中国标准时间) Date 对象有以下几种创建方式: 1. let date = new Date();2. let date = new Date(milliseconds);3. let date = new Date(dateString);4. l

js 校验时间格式

1.获取用户输入的时间: var bagin = $('.input_one').val(); 2.验证时间格式是否正确:(验证通过返回时间戳格式,例如:(2017-01-01,2017,-,01,-,01),否则返回null) ar bagin_r = bagin.match(/^(\d{4})(-)(\d{2})(-)(\d{2})$/); if(bagin_r==null){ alert("请输入正确的开始时间格式,如:2017-01-01"); return false; }

js 格林威治时间转正常格式并兼容ios

function timeChange(time) { var date = time.substr(0, 10); //年月日 var hours = time.substring(11, 13); var minutes = time.substring(14, 16); var seconds = time.substring(17, 19); var timeFlag = date + ' ' + hours + ':' + minutes + ':' + seconds; timeFl

JS中时间格式转换

DateBox1.GetValue(); //获取到DateBox1的值 //Tue Feb 26 2019 00:00:00 GMT+0800 (中国标准时间) 执行会显示你控件所选择的时间 var d=DateBox1.GetValue(); var a=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.get