I need to convert a date in format eg. 2011-01-02 to a unix timestamp in JavaScript but do not exactly know how to accomplish it. I can get the current timestamp using the following functions Math.round((new Date()).getTime() / 1000); but do not know how to convert the given date to a unix timestamp?
Add a comment
|
1 Answer
You can write new Date("2011-01-02").getTime() / 1000
3 Comments
Jeremy
RobG
Noting that "2011-01-02" will be parsed as UTC, not local as may be expected by those familiar with ISO 8601 but not ECMA-262. ;-)
Kenzo
Im here because I can't find a way to get YYYY-MM-DD into a locally correct timestamp....