Skip to content

Instantly share code, notes, and snippets.

@ttanimichi
Last active August 29, 2015 14:21
Show Gist options
  • Save ttanimichi/6cf5c87baef5e5df9a71 to your computer and use it in GitHub Desktop.
Save ttanimichi/6cf5c87baef5e5df9a71 to your computer and use it in GitHub Desktop.
プロダクションでは moment.js 使ったほうがいいです
'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;
}
}
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