Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 17th, 2012  |  syntax: None  |  size: 0.47 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Javascript Converting human time to timestamp
  2. var d = new Date("Wed Jun 20 19:20:44 +0000 2012");
  3. d.getTime(); //returns 1340220044000
  4.  
  5. //OR
  6.  
  7. Date.parse("Wed Jun 20 19:20:44 +0000 2012"); //returns 1340220044000
  8.        
  9. //if you want to truncate ms instead of rounding just use Math.floor()
  10. Math.round(Date.parse("Wed Jun 20 19:20:44 +0000 2012") / 1000); //returns 1340220044
  11.        
  12. //Gets date in seconds
  13. var d1 = Date.parse('Wed Jun 20 19:20:44 +0000 2012')/1000;
  14. alert(d1);