Created
January 11, 2017 08:12
-
-
Save JacksonTian/595ddb8a82639b4c9b5ca94dcd64274f to your computer and use it in GitHub Desktop.
TIME format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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