A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [CS3] converting milliseconds to hours and minutes

  1. #1
    Member
    Join Date
    May 2007
    Posts
    44

    Lightbulb [CS3] converting milliseconds to hours and minutes

    I have 2 Date objects and count down from now to ready,
    and show it in the format of "00 HOURS and 00 MINS."
    Code:
    var now:Date = new Date();
    var ready:Date = new Date(2008,9,10,12,0,0);
    
    var dif:Number = (ready.valueOf() - now.valueOf());
    trace(dif);
    How can I convert difference to HOUR + MIN?

    Please help.

    P.S. I`m using A.S. 3.0

  2. #2
    Senior Member Computer Dork's Avatar
    Join Date
    Mar 2001
    Location
    St. Louis
    Posts
    1,026
    well, if seconds are 1000 milliseconds...

    var totalSeconds:int = Math.round(dif/1000);

    so for minutes you would do this:

    var minsLeft:int = Math.round(totalSeconds/60);

    and hours...

    var hoursLeft:int = Math.round((totalSeconds/60)/60);


    see if that works for you.

  3. #3
    Banned deepakflash's Avatar
    Join Date
    Aug 2007
    Location
    [Object not found]
    Posts
    1,160
    milkman, did that work?

  4. #4
    Senior Member Computer Dork's Avatar
    Join Date
    Mar 2001
    Location
    St. Louis
    Posts
    1,026
    You'll have to add in some more logic to make sure that 3:01 doesn't show up as 3:1... but other than that, it should work unless my math is off.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center