Created
August 21, 2012 06:01
-
-
Save musubu/3412473 to your computer and use it in GitHub Desktop.
JavaScriptのDateをMySQLのdatetimeに入力できる書式に変換する
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 str_created_at = 'Sun Dec 11 21:44:28 +0000 2011'; | |
var created_at = new Date(str_created_at); | |
console.log(created_at) | |
// Mon Dec 12 2011 06:44:28 GMT+0900 (JST) | |
function toUTCDatetime (date, callback) { | |
try { | |
var result = date.getUTCFullYear() + "-" + date.getUTCMonth() + "-" + date.getUTCDate() + " " + date.getUTCHours() + ":" + date.getUTCMinutes() + ":" + date.getUTCSeconds(); | |
callback(null, result); | |
} catch (err) { | |
callback(err, null); | |
} | |
} | |
toUTCDatetime(created_at, function(err, str) { | |
console.log(str) | |
// 2011-11-11 21:44:28 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment