PDA

View Full Version : reduce the time on a clock by 5 minutes



Jay Dog
11-14-2013, 11:44 AM
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


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;

coothead
11-14-2013, 05:12 PM
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...


var minutes = time.getMinutes()-5


coothead

Jay Dog
11-15-2013, 11:22 AM
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 :-)

coothead
11-15-2013, 11:51 AM
No problem, you're very welcome. ;)



coothead

Jay Dog
11-15-2013, 12:01 PM
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

coothead
11-15-2013, 12:55 PM
Hi there Jay Dog,

I am sorry about that error of mine. :o

I have amended the action script to this...


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

jscheuer1
11-15-2013, 01:32 PM
That looks like it should work. Often what's done though is like so:


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.

coothead
11-15-2013, 01:51 PM
Hi there John,





time.setMinutes(time.getMinutes() - 5);

That is what distinguishes the professional coder from the amateur. :D

coothead

Jay Dog
11-21-2013, 04:27 PM
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;

coothead
11-22-2013, 10:35 AM
Hi there Jay Dog,

this...


if (month = 1) {
month = "January";
}
...should be...


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

Alternatively you could try it like this...


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

keyboard
12-07-2013, 10:48 AM
Closing this due to excessive spam. If anyone needs it reopened just message me or another moderator.