Created
February 5, 2016 02:47
-
-
Save liunian/776dcc89ab953c0aae49 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
/** | |
* 把 2014-02-02 15:30:20 转换为 Date 对象, | |
* iOS Safari 仅支持 1995-12-17T03:24:00 格式,故对更常用的无 T 的需额外处理 | |
* | |
* @param {String} dateString - 待转换的时间字符串,格式形如 2014-02-02 15:30:20 | |
* | |
* @return {Date} - 转换后的 Date 对象 | |
*/ | |
function parseDate(dateString) { | |
var arr = dateString.split(/[- :]/); | |
return new Date(arr[0], arr[1] - 1, arr[2], arr[3] || '0', arr[4] || '0', arr[5] || '0'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment