• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Current Date into Seconds

New Here ,
May 27, 2012 May 27, 2012

Copy link to clipboard

Copied

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 😃

TOPICS
ActionScript

Views

738

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 27, 2012 May 27, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 29, 2012 May 29, 2012

Copy link to clipboard

Copied

LATEST

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines