Created
November 15, 2013 06:00
-
-
Save daneko/7479824 to your computer and use it in GitHub Desktop.
mongoで時間出力の見た目を整形したくてjavascript書きました
javascript力がなさすぎて悲しくなる
javascript date format
This file contains 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 dformat = function(d){ | |
var utc = d.getTime() + (d.getTimezoneOffset() * 60000); | |
var date = new Date(utc); | |
var tos = function(t){ | |
if(t < 10) return "0" + t; | |
return "" + t; | |
} | |
var y = tos(date.getFullYear()); | |
var M = tos(date.getMonth() + 1); | |
var d = tos(date.getDate()); | |
var h = tos(date.getHours()); | |
var m = tos(date.getMinutes()); | |
var s = tos(date.getSeconds()); | |
var ymd = [ y, M, d].reduce(function(tmp,val){return tmp + "-" + val}); | |
var hms = [ h, m, s].reduce(function(tmp,val){return tmp + ":" + val}); | |
return ymd + " " + hms; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment