iso 8601 to as3 date object


/ Published in: ActionScript 3
Save to your folder(s)

probably not the best way but easy enough


Copy this code and paste it in your HTML
  1. //trace(new Date("2010/05/03T14:14Z")); ----> this will error 'invalid date'
  2.  
  3. var isoDate = "2010-05-03T14:14Z";
  4.  
  5. //this will remove the T and Z
  6. var date = isoDate.replace(/[A-Z]/gi," ");
  7.  
  8. //this will replace the hypens with forward slashes
  9. date = date.replace(/\-/gi, "/");
  10.  
  11. //this casts the string to date and creates the correct date object
  12. trace(new Date(date));

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.