Skip to content

Instantly share code, notes, and snippets.

@JacksonTian
Created January 11, 2017 08:12
Show Gist options
  • Save JacksonTian/595ddb8a82639b4c9b5ca94dcd64274f to your computer and use it in GitHub Desktop.
Save JacksonTian/595ddb8a82639b4c9b5ca94dcd64274f to your computer and use it in GitHub Desktop.
TIME format
'use strict';
function pad(value) {
return (value < 10) ? '0' + value : '' + value;
}
class Time {
constructor(date) {
this.d = date;
}
get YYYY(){
return '' + this.d.getUTCFullYear();
}
get MM() {
return pad(this.d.getUTCMonth() + 1);
}
get DD() {
return pad(this.d.getUTCDate());
}
get HH() {
return pad(this.d.getUTCHours());
}
get mm() {
return pad(this.d.getUTCMinutes());
}
get ss() {
return pad(this.d.getUTCSeconds());
}
}
var t = new Time(new Date());
function tag(strings, ...values) {
console.log(arguments);
}
// 删除掉毫秒部分
tag`${t.YYYY}-${t.MM}-${t.DD}T${t.HH}:${t.mm}:${t.ss}Z`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment