Skip to content

Instantly share code, notes, and snippets.

@reejosamuel
Created July 23, 2016 18:58
Show Gist options
  • Save reejosamuel/ed320c3c4905ee0a49bac489e2968b54 to your computer and use it in GitHub Desktop.
Save reejosamuel/ed320c3c4905ee0a49bac489e2968b54 to your computer and use it in GitHub Desktop.
Parse the default timestamp from rails in javascript
function parseRailsTime(iso8601) {
var s = $.trim(iso8601);
s = s.replace(/\.\d+/,""); // remove milliseconds
s = s.replace(/-/,"/").replace(/-/,"/");
s = s.replace(/T/," ").replace(/Z/," UTC");
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
s = s.replace(/([\+\-]\d\d)$/," $100"); // +09 -> +0900
return new Date(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment