Last active
August 29, 2015 14:21
-
-
Save ttanimichi/6cf5c87baef5e5df9a71 to your computer and use it in GitHub Desktop.
プロダクションでは moment.js 使ったほうがいいです
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'; | |
class Time { | |
constructor(time) { | |
this.time = time; | |
} | |
getHours() { | |
return Math.floor((this.time / 1000 / 3600) % 24); | |
} | |
getMinutes() { | |
return Math.floor((this.time / 1000 / 60) % 60); | |
} | |
getSeconds() { | |
return Math.floor((this.time / 1000) % 60); | |
} | |
getMilliseconds() { | |
return this.time % 1000; | |
} | |
} |
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
var time_ms = 45296789; | |
var time_sec = time_ms / 1000; | |
var ms = time_ms % 1000; | |
var sec = Math.floor(time_sec % 60); | |
var min = Math.floor((time_sec / 60) % 60); | |
var hour = Math.floor((time_sec / 3600) % 24); | |
console.log("ms:" + ms); | |
console.log("sec:" + sec); | |
console.log("min:" + min); | |
console.log("hour:" + hour); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment