Server time (Macromedia Flash clock)

By telleropnul, June 22, 2016

Create a clock in Macromedia Flash containing an hourHand, minuteHand and secondHand.

Then, add the following actionscript:

Load = function() {
 now_init = new Date();
 daysummertime = (31 - 5*now_init.getFullYear/4 - now_init.getFullYear/100 -now_init.getFullYear/400 +5) % 7;
 daywintertime = (31 - 5*now_init.getFullYear/4 - now_init.getFullYear/100 -now_init.getFullYear/400 +2) % 7;
 dateSummerTime = new Date(now_init.getFullYear, 3, daysummertime);
 dateWinterTime = new Date(now_init.getFullYear, 10, daywintertime);
};
_root.onEnterFrame = function() {
 now = new Date();
 // This script supports an external 'seconds since 1970' value.
 // If not set, the value will be set based on the clients current time.
 // The idea is that an external 'seconds since 1970 date/time' value can
 // be provided.  This way, the script will calculate the elapsed time
 // relative to this fixed time/date value.  This is useful is you would
 // want to pass the webserver current date/time to the clock script and
 // calculate and display the elapsed time from there by the client.
 // Note: with Flash, elapsed time can only be calculated by the client.
 // milliseconds elapsed
 if (s_ext == undefined) {
 d = now.getMilliseconds();
 s = now.getSeconds();
 m = now.getMinutes();
 h = now.getHours();
 hourHand._rotation = h*30+m/2;
 minuteHand._rotation = m*6+s/10;
 // Ticking clock
 // secondHand._rotation = s*6;
 // Smooth clock
 secondHand._rotation = s*6+d/156;
 if (h>11) {
 txt_ampm.text = "PM";
 } else {
 txt_ampm.text = "AM";
 }
 } else {
 d_elapsed = new Number(now.getTime()-now_init.getTime());
 d_now = new Number(d_elapsed+(s_ext*1000));
 now1 = new Date(d_now);
 d1 = now1.getUTCMilliseconds();
 s1 = now1.getUTCSeconds();
 m1 = now1.getUTCMinutes();
 h1 = now1.getUTCHours();
 // External Time Offset due to Time Zone differences
 //h1 = h1 +2;
 // If your external time web server is located in a timezone 
 // with daylight savings time, we have to use a formula
 // to calculate the (varying) offset value
 if (now1>datesummertime && now1
 h1 = h1 + 2;
 } else {
 h1 = h1 + 1;
 }
 // Update clock hands  
 hourHand._rotation = h1*30+m1/2;
 minuteHand._rotation = m1*6+s1/10;
 // Ticking clock
 // secondHand._rotation = s1*6;
 // Smooth clock
 secondHand._rotation = s1*6+d1/156;
 if (h1>11) {
 txt_ampm.text = "PM";
 } else {
 txt_ampm.text = "AM";
 }

Source Files