日期时间
GMT
UTC
时间戳
1. UTC是根据原子钟来计算时间,而GMT是根据地球的自转和公转来计算时间。
2. UTC是现在用的时间标准,GMT是老的时间计量标准。UTC更加精确,由于现在世界上最精确的原子钟50亿年才会误差1秒,可以说非常精确。
3. 中国 = UTC+8
4. UTC === GMT
5. ISO标准 该标准称为 ISO-8601 ,格式为: YYYY-MM-DDTHH:mm:ss.sssZ
1. Date.parse(new Date())
2. new Date().getTime()
3. new Date().valueOf()
1. parse()
2. getTime()
3. valueOf()
3. setDate()
1. toDateString()
2. toISOString()
3. toJSON()
4. toLocaleDateString()
5. toLocaleTimeString()
6. toTimeString()
7. toString()
8. toUTCString()
时间转换
export function GMTToSecond(time) {
function addDateZero(num) {
return (num < 10 ? "0" + num : num);
}
function addDateTwoZero(num) {
if(num<100&&num>=10){
return "0"+num
}
else if(num<10){
return "00"+num
}
else{
return num
}
}
let date = new Date(time)
let Str=date.getFullYear() + '-' +
addDateZero(date.getMonth() + 1) + '-' +
addDateZero(date.getDate()) + ' ' +
addDateZero(date.getHours()) + ':' +
addDateZero(date.getMinutes()) + ':' +
addDateZero(date.getSeconds())
return Str
}
export function GMTToStr(time) {
function addDateZero(num) {
return (num < 10 ? "0" + num : num);
}
function addDateTwoZero(num) {
if(num<100&&num>=10){
return "0"+num
}
else if(num<10){
return "00"+num
}
else{
return num
}
}
let date = new Date(time)
let Str=date.getFullYear() + '-' +
addDateZero(date.getMonth() + 1) + '-' +
addDateZero(date.getDate()) + ' ' +
addDateZero(date.getHours()) + ':' +
addDateZero(date.getMinutes()) + ':' +
addDateZero(date.getSeconds())+ '.'+
addDateTwoZero(date.getMilliseconds())
return Str
}
Date.format(‘xxx’) 格式输出
export function timestampToDate(timestamp) {
let date = new Date();
date.setTime(timestamp * 1000);
return date
}
timestampToDate('1484222693')
function timestampFormatDate(timestamp, format) {
let date = timestampToDate(timestamp)
return date.format(format)
}
timestampFormatDate('1484222693', 'yyyy-MM-dd');
const _default = {
install: function (App, options) {
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;
}
}
}
export default _default;
function formateDate(datetime) {
function addDateZero(num) {
return (num < 10 ? "0" + num : num);
}
let d = new Date(datetime);
let formatdatetime = d.getFullYear() + '-' + addDateZero(d.getMonth() + 1) + '-' + addDateZero(d.getDate());
return formatdatetime;
},
夏令时和冬令时(美国)
1.GMT
格林威治标准时间GMT
2.UTC
UTC指的是Coordinated Universal Time- 世界协调时间(又称世界标准时间、世界统一时间)
所以基本上UTC的本质强调的是比GMT更为精确的世界时间标准,不过对于现行表款来说,GMT与UTC的功能与精确度是没有差别的。
3.PDT
PDT 是 Pacific Daylight Time 的缩写。
美国夏季始于每年4月的第1个周日,止于每年10月的最后一个周日。夏令时比正常时间早一小时,与PDT时间相对应的是PST , Pacific Standard Time 。 夏时制结束后就是PST。
4.PST
PST是太平洋标准时间(西八区),与北京时间(东八区)时差-16个小时,也就是北京时间减去16就是PST时间。而PDT比PST早1个小时,就是说PDT与北京时间时差为-15小时。
美国横跨西五区至西十区,共六个时区。每个时区对应一个标准时间,从东向西分别为
东部时间(EST)(西五区时间)、
中部时间(CST)(西六区时间)、
山地时间(MST)(西七区时间)、
太平洋时间(西部时间)(PST)(西八区时间)、
阿拉斯加时间(AKST)(西九区时间)
夏威夷时间(HST)(西十区时间),
按照“东早西晚”的规律,各递减一小时。
美国标准时间 | 与北京时间时差(小时) |
---|
HST | -18 |
AKST | -17 |
PST | -16 |
MST | -15 |
CST | -14 |
EST | -13 |
夏季始于每年4月的第1个周日,止于每年10月的最后一个周日。也称为DST: Daylight Saving Time
美国夏季时间 | 与北京时间时差(小时) |
---|
HDT | -17 |
AKDT | -16 |
PDT | -15 |
MDT | -14 |
CDT | -13 |
EDT | -12 |