Created
June 25, 2015 13:52
-
-
Save magnet88jp/40ac2fd4c141d88aac80 to your computer and use it in GitHub Desktop.
Utility of JavaScript
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 from date format string to date | |
var convertDateFromStr = function(dateStr) { | |
var newDt = new Date(); | |
var reg = new RegExp('\\-|\\/|\\s|T'); | |
var dt = dateStr.split(reg, 4); | |
if(dt.length > 2) { | |
newDt = new Date(dt[0], dt[1]-1, dt[2]); | |
if(dt.length > 3) { | |
var tm = dt[3].split(':', 3); | |
if(tm.length == 3) { | |
newDt = new Date(dt[0], dt[1]-1, dt[2], tm[0], tm[1], tm[2]); | |
} else if (tm.length == 2) { | |
newDt = new Date(dt[0], dt[1]-1, dt[2], tm[0], tm[1]); | |
} | |
} | |
} | |
return newDt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment