The Javascript Date object has a number of functions for working with dates and times. The getTime() method returns the millisecond representation of the Date object and this post shows how to convert this to a UNIX timestamp.
To convert the current date and time to a UNIX timestamp do the following:
getTime() returns milliseconds from the UNIX epoch, so divide it by 1000 to get the seconds representation. It is rounded using Math.round() to make it a whole number. The "ts" variable now has the UNIX timestamp for the current date and time relevent to the user's web browser.
0 comments:
Post a Comment