Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: reduce the time on a clock by 5 minutes

  1. #1
    Join Date
    Oct 2012
    Location
    England
    Posts
    103
    Thanks
    28
    Thanked 2 Times in 1 Post

    Default reduce the time on a clock by 5 minutes

    Hi,

    I really like the clock posted here:

    http://www.flashfridge.com/tutorial.asp?ID=49

    I have used a modified version of it for our video presentation screens at the school reception, however, for some reason which I simply don't know why, the screens are five minutes fast, for example, when it says 11.22 here in my office, it says 11.22 on the flash file HERE, when I publish it on the reception screens, it will say 11.27 THERE.

    There is no problem with the code, that is fine, it is something to do with the screen set up... very complicated and beyond me I'm afraid... however, is there a simple way that I can alter the ActionScript so that although it's 11.22 in my office and of course 11.22 in reception, the code bit will say it's actually 11.17 BUT when it's on the screen because of the 5 minute discrepancy it will now say 11.22... does that make sense? It's just the actionscript code that I need to reduce by 5 minutes.

    Many thanks,


    Jay Dog

    Code:
    time=new Date(); // time object
    var seconds = time.getSeconds()
    var minutes = time.getMinutes()
    var hours = time.getHours()
    if (hours<12) {
    	ampm = "AM";
    } 
    	else{
    	ampm = "PM";
    }
    while(hours >12){
    	hours = hours - 12;
    }
    if(hours<10)
    	{
    	hours = "0" + hours;
    }
    if(minutes<10)
    	{
    	minutes = "0" + minutes;
    }
    if(seconds<10)
       {
    	seconds = "0" + seconds;
    }
    Clock_text.text = hours + ":" + minutes + ":" + seconds +" "+ ampm;

  2. #2
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    2,447
    Thanks
    5
    Thanked 292 Times in 285 Posts

    Default

    Hi there Jay Dog,

    what you require is known as a "Bosses Clock".

    You can find a working example within the attachment.

    This is how it was created...
    Code:
    
    var minutes = time.getMinutes()-5

    coothead
    Attached Files Attached Files

  3. The Following User Says Thank You to coothead For This Useful Post:

    Jay Dog (11-15-2013)

  4. #3
    Join Date
    Oct 2012
    Location
    England
    Posts
    103
    Thanks
    28
    Thanked 2 Times in 1 Post

    Default

    Hi thanks, I'll have a play with it later today. As daft as it sounds I was actually in main reception of school today with a stop watch and when the reception screen said 11.00 am I pressed the watch, went back to my office and stopped it when the bell went... 5 minutes and 44 seconds discrepancy... lordy knows why...

    did find a good sample which I thought worked, it was OK at say 11.20 as I could set it 5 mins slow and it'd show 11.15 in my room but 11.20 in the reception, but when it got to 12.00pm it would just show 12.-05pm. Thanks for your help man :-)

  5. #4
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    2,447
    Thanks
    5
    Thanked 292 Times in 285 Posts

    Default


    No problem, you're very welcome.


    coothead

  6. #5
    Join Date
    Oct 2012
    Location
    England
    Posts
    103
    Thanks
    28
    Thanked 2 Times in 1 Post

    Default

    Hi Man,

    sorry that didn't work, it's OK if you're 12.05 and higher but anything below that, such as 12.04 it reads as 12.-01

    Any extra help'd be greatly appreciated, cheers

  7. #6
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    2,447
    Thanks
    5
    Thanked 292 Times in 285 Posts

    Default

    Hi there Jay Dog,

    I am sorry about that error of mine.

    I have amended the action script to this...
    Code:
    
    time=new Date(); // time object
    var seconds = time.getSeconds();
    var minutes = time.getMinutes()-5;
    var hours = time.getHours();
    if (minutes<0){
        minutes=60+minutes;
        hours=hours-1;
     }
    if (hours<12) {
    	ampm = "AM";
     } 
    	else{
    	ampm = "PM";
     }
    while(hours >12){
    	hours = hours - 12;
    }
    if(hours<10)
    	{
    	hours = "0" + hours;
    }
    if(minutes<10)
    	{
    	minutes = "0" + minutes;
    }
    if(seconds<10)
       {
    	seconds = "0" + seconds;
    }
    Clock_text.text = hours + ":" + minutes + ":" + seconds +" "+ ampm;
    Test out this replacement attachment.


    coothead
    Attached Files Attached Files
    Last edited by coothead; 11-15-2013 at 04:07 PM. Reason: grammatical error

  8. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That looks like it should work. Often what's done though is like so:

    Code:
    time=new Date(); // time object
    time.setMinutes(time.getMinutes() - 5);
    From that line on the time will be 5 minutes earlier. So whatever other information is taken from it will be accurately calculated on that basis, including not only the minutes and hour, but also the date and year, should either of those be affected.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #8
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    2,447
    Thanks
    5
    Thanked 292 Times in 285 Posts

    Default

    Hi there John,

    Code:
    
    time.setMinutes(time.getMinutes() - 5);
    That is what distinguishes the professional coder from the amateur.

    coothead

  10. #9
    Join Date
    Oct 2012
    Location
    England
    Posts
    103
    Thanks
    28
    Thanked 2 Times in 1 Post

    Default

    Hi, trying to add month names to the code, it worked well when I added

    if (month = 11) {
    month = "November";
    }


    to it but when I added the other month names it says the month now is December.

    I have tried shifting the months along one, so that

    I think for some reason, it displays the last month name in the code...



    time = new Date();
    var today = new Date();
    var dat = today.getDate();
    var month = today.getMonth() + 1;
    var year = today.getFullYear();
    var dayN = today.getDay();
    //time object
    var seconds = time.getSeconds() - 29;
    var minutes = time.getMinutes() - 5;
    var hours = time.getHours();
    if (month = 1) {
    month = "January";
    }
    if (month = 2) {
    month = "February";
    }
    if (month = 3) {
    month = "March";
    }
    if (month = 4) {
    month = "April";
    }
    if (month = 5) {
    month = "May";
    }
    if (month = 6) {
    month = "June";
    }
    if (month = 7) {
    month = "July";
    }
    if (month = 8) {
    month = "August";
    }
    if (month = 9) {
    month = "September";
    }
    if (month = 10) {
    month = "October";
    }
    if (month = 11) {
    month = "November";
    }
    if (month = 12) {
    month = "December";
    }
    if (seconds < 0) {
    seconds = 60 + seconds;
    minutes = minutes - 1;
    }
    if (minutes < 0) {
    minutes = 60 + minutes;
    hours = hours - 1;
    }
    while (hours > 12) {
    hours = hours - 12;
    }
    if (hours < 10) {
    hours = "0" + hours;
    }
    if (minutes < 10) {
    minutes = "0" + minutes;
    }
    if (seconds < 10) {
    seconds = "0" + seconds;
    }
    Clock_text.text = hours + ":" + minutes + ":" + seconds + " " + dat + " " + month + " " + year;

  11. #10
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    2,447
    Thanks
    5
    Thanked 292 Times in 285 Posts

    Default

    Hi there Jay Dog,

    this...
    Code:
    
    if (month = 1) {
    month = "January";
    }
    ...should be...
    Code:
    
    if (month == 1) {
    month = "January";
    }
    ...and similarly for the other eleven.

    Alternatively you could try it like this...
    Code:
    
    var ary=["February","February","March","April","May","June","July",
             "August","September","October","November","December"];
    time = new Date();
    var today = new Date();
    var dat = today.getDate();
    var month=ary[today.getMonth()];
    var year = today.getFullYear();
    var dayN = today.getDay();
    //time object
    var seconds = time.getSeconds() - 29;
    var minutes = time.getMinutes() - 5;
    var hours = time.getHours();
    if (seconds < 0) {
    seconds = 60 + seconds;
    minutes = minutes - 1;
    }
    if (minutes < 0) {
    minutes = 60 + minutes;
    hours = hours - 1;
    }
    while (hours > 12) {
    hours = hours - 12;
    }
    if (hours < 10) {
    hours = "0" + hours;
    }
    if (minutes < 10) {
    minutes = "0" + minutes;
    }
    if (seconds < 10) {
    seconds = "0" + seconds;
    }
    Clock_text.text = hours + ":" + minutes + ":" + seconds + " " + dat + " " + month + " " + year; 
    coothead

Similar Threads

  1. time clock
    By discdemo in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 07-29-2010, 07:29 AM
  2. Time Clock based on GMT
    By HilaryJ in forum JavaScript
    Replies: 0
    Last Post: 02-09-2010, 01:03 AM
  3. I'm looking for a Time Clock
    By ssschlam in forum Looking for such a script or service
    Replies: 1
    Last Post: 01-08-2008, 04:42 PM
  4. Local Time Clock
    By andre@swakop.com in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 04-10-2007, 01:53 PM
  5. Regarding date-time clock ...
    By lprag in forum Dynamic Drive scripts help
    Replies: 14
    Last Post: 02-23-2006, 12:24 PM

Bookmarks

Posting Permissions

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