Created
September 8, 2011 12:45
-
-
Save wesen/1203315 to your computer and use it in GitHub Desktop.
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
/** | |
* Convert a mysql timestamp to javascript, taking the timezone into account. | |
**/ | |
function mysqlToDate(timestamp) { | |
var months = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; | |
var regex = /^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9])T([0-2][0-9]):([0-5][0-9]):([0-5][0-9])(.*)/; | |
var parts = timestamp.replace(regex,"$2/ $3, $1 $4:$5:$6 GMT$7").split('/'); | |
var str = months[parseInt(parts[0])] + parts[1]; | |
return new Date(str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment