Skip to content

Instantly share code, notes, and snippets.

@shingorow
Created August 24, 2017 10:57
Show Gist options
  • Save shingorow/20b3cf52d1ee375f6972efecd013ef55 to your computer and use it in GitHub Desktop.
Save shingorow/20b3cf52d1ee375f6972efecd013ef55 to your computer and use it in GitHub Desktop.
JavaScript で秒や分を別の時間単位に変換する ref: http://qiita.com/shingorow/items/62eae5a87c85d1bcd0d2
(function (global) {
var TimeConvert = (function () {
function TimeConvert() {}
TimeConvert.prototype.sec2min = function (time) {
var min = Math.floor(time / 60);
var sec = time % 60;
return {
min: min,
sec: sec
}
}
TimeConvert.prototype.min2hour = function (time) {
var hour = Math.floor(time / 60);
var min = time % 60;
return {
hour: hour,
min:min
}
}
TimeConvert.prototype.sec2hour = function (time) {
var sec = (time % 60) % 60;
var min = Math.floor(time / 60) % 60;
var hour = Math.floor(time / 3600);
return {
hour: hour,
min: min,
sec: sec
}
}
return TimeConvert;
})();
global.TimeConvert = TimeConvert;
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment