Created
August 16, 2014 21:31
-
-
Save enlacee/7bfb877e799c7851ac0e to your computer and use it in GitHub Desktop.
get dateTime of string of date in native 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
/** | |
* function setting datetime compatible multiple navigator chrome and firefox | |
* @param stringDate 2014-07-28 03:42:23 | |
*/ | |
function _settingDateTime(stringDate) { | |
var myDate = new Date(); | |
//string | |
var arrayDate = stringDate.split(' '); | |
if (arrayDate.length > 0) { | |
var date = arrayDate[0]; | |
var time = arrayDate[1]; | |
var dateSplit = date.split('-'); | |
var timeSplit = time.split(':'); | |
myDate.setFullYear (dateSplit[0]); | |
myDate.setMonth (dateSplit[1]-1); | |
myDate.setDate (dateSplit[2]); | |
myDate.setHours (timeSplit[0]); | |
myDate.setMinutes (timeSplit[1]); | |
myDate.setSeconds(timeSplit[2]); | |
} else { | |
myDate = false; | |
} | |
return myDate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment