Skip to content

Instantly share code, notes, and snippets.

@doxavore
Created July 6, 2011 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doxavore/1067561 to your computer and use it in GitHub Desktop.
Save doxavore/1067561 to your computer and use it in GitHub Desktop.
fromString: function (dateString) {
if (!dateString) { return new Date(); }
// IE/Safari expects "2011/05/03 09:03:21-0500"
if (dojo.isIE || dojo.isSafari) {
// Replace hyphens with forward slashes (2011-05-03 => 2011/05/03)
dateString = dateString.replace(/^(\d{4})-(\d{2})-(\d{2})/, "$1/$2/$3");
// Replace T prefixing time with a space (T09:03:21 => " 09:03:21")
dateString = dateString.replace(/T(\d+:\d+:\d+)/, " $1");
// Remove colon in timezone (-05:00 => -0500)
dateString = dateString.replace(/([\-\+])(\d+):(\d+)$/, "$1$2$3");
}
return new Date(dateString);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment