2 Replies Latest reply on May 29, 2012 7:49 AM by dmeN

Current Date into Seconds

Hey guys

I already know, that I can show my realtime with the date-class. But it makes me crazy how I get the minutes and hours into seconds (in realtime).
All I want to have is a Number counting up with every second. A number that doesn't start again after it reaches 60.

For example, there is the current time of 3.45 am, so I want to have a number of seconds like 13500. 14.00 pm a number 50400 and so on... (and at the and of the day a total of 86400 seconds).

Hope you can help me^^

• 1. Re: Current Date into Seconds

You should be able to use the getTime() method of the Date class which returns the number of milliseconds since midnight January 1, 1970.  Get the getTime() value for the 0 hour of the current day, then subtract that from the current getTime() value and divide by 1000 to convert it to seconds.

• 2. Re: Current Date into Seconds

You should be able to just use the current time of the day with new Date()

Just take the (current hours +1) * 3600 and you get the number of seconds so far including the all the seconds for the current hour

Then subtract the seconds in the minutes remaining in the hour

Then add the seconds into the current minute...

This should do:

function getSeconds():int

var curDateTime:Date = new Date();

var totalSeconds:int = (curDateTime.hours + 1) * 3600;

var secondsRemainingInHour:int = (60 - curDateTime.minutes) * 60;