Skip navigation
Sailem12
Currently Being Moderated

Current Date into Seconds

May 27, 2012 6:54 PM

Tags: #problem #as3 #convert #date #current #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^^

Answers are welcome =)

 
Replies
  • Currently Being Moderated
    May 27, 2012 7:25 PM   in reply to Sailem12

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 29, 2012 7:49 AM   in reply to Sailem12

    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;

         return totalSeconds - secondsRemainingInHour + curDateTime.seconds;

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points