Jump to content

Javascript Dates


Guest Reveneous
 Share

Recommended Posts

Guest Reveneous

Hi all,i wonna know if its possible to subtract 2 dates with javascript. One you set manual(1) and one the date of today(2).I want to make a time that shows how much time still to go to time. So time(1) - time(2)Thanks allot!

Link to comment
Share on other sites

Read about the Date object here: http://www.w3schools.com/js/js_obj_date.aspThe getTime() method returns a timestamp in milliseconds. Simple arithmetic can convert that to seconds, hours, days etc.The documentation does not explain that you can pass Date() a timestamp and get a time in the future or past. So if you got a timestamp for now, subtracted/added a certain number of milliseconds, you could pass the result to Date() and get a date object for some time in the past or future.Be sure to pass the milliseconds to Date() as a string, not a number.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...