world clock gamemaker

Information about object: obj_world_clock
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

///set up variables
//set time zone
date_set_timezone(timezone_utc);//get local time
london_hour=0;
london_minute=0;
london_second=0;
newyork_hour=0;
newyork_minute=0;
newyork_second=0;
sydney_hour=0;
sydney_minute=0;
sydney_second=0;

Step Event:
execute code:

//calculations will differ depending where in the world you are
london_hour=date_get_hour(date_current_datetime());//get local time
london_minute=date_get_minute(date_current_datetime());//get local time
london_second=date_get_second(date_current_datetime());//get local time
newyork_hour=(london_hour+19+24) mod 24;//set newyork time
newyork_minute=london_minute;
newyork_second=london_second;
sydney_hour=(london_hour+10) mod 24;//set sydney time
sydney_minute=london_minute;
sydney_second=london_second;

london_hour_string=string(london_hour);
if string_length(london_hour_string)==1 london_hour_string="0"+london_hour_string;
london_minute_string=string(london_minute);
if string_length(london_minute_string)==1 london_minute_string="0"+london_minute_string;
london_second_string=string(london_second);
if string_length(london_second_string)==1 london_second_string="0"+london_second_string;

newyork_hour_string=string(newyork_hour);
if string_length(newyork_hour_string)==1 newyork_hour_string="0"+newyork_hour_string;
newyork_minute_string=string(newyork_minute);
if string_length(newyork_minute_string)==1 newyork_minute_string="0"+newyork_minute_string;
newyork_second_string=string(newyork_second);
if string_length(newyork_second_string)==1 newyork_second_string="0"+newyork_second_string;

sydney_hour_string=string(sydney_hour);
if string_length(sydney_hour_string)==1 sydneyhour_string="0"+sydney_hour_string;
sydney_minute_string=string(sydney_minute);
if string_length(sydney_minute_string)==1 sydney_minute_string="0"+sydney_minute_string;
sydney_second_string=string(sydney_second);
if string_length(sydney_second_string)==1 sydney_second_string="0"+sydney_second_string;

Draw Event:
execute code:

//draw times
draw_text(50,50,"london "+london_hour_string+":"+london_minute_string+" - "+london_second_string);
draw_text(50,150,"newyork "+newyork_hour_string+":"+newyork_minute_string+" - "+newyork_second_string);
draw_text(50,250,"sydney "+sydney_hour_string+":"+sydney_minute_string+" - "+sydney_second_string);

No comments:

When Bad People Make Good Art

I offer six guidelines on cancel culture ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏...

Contact Form

Name

Email *

Message *