FrozenHaddock Tutorials: Date and Time

In this tutorial, you will learn how to display the system date and time in dynamic text boxes.

Display the date

First of all create a new dynamic text box, for more info see basic variables, and change the var: value to datedisplay. Once this is done, add the following code into the frame actions.

datedisplay = new Date();
weekday = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
month = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
datedisplay = (weekday[datedisplay.getDay()]+" "+datedisplay.getDate()+" "+month[datedispay.getMonth()]+" "+datedisplay.getFullYear());

This will display the date in Monday 15 July format. To show it in other formats, swap or remove the pieces between the +'s

Display the time

This time create a dynamic text box and set the var: value to timedisplay. Then add the following into the frame actions.

timedisplay = new Date();
var hours = timedisplay.getHours()>9 ? timedisplay.getHours() : "0"+timedisplay.getHours();
var minutes = timedisplay.getMinutes()>9 ? timedisplay.getMinutes() : "0"+timedisplay.getMinutes();
var seconds = timedisplay.getSeconds()>9 ? timedisplay.getSeconds() : "0"+timedisplay.getSeconds();
timedisplay = (hours + " . " + minutes + " : " + seconds);

This will display the time as Hour:Minute:Seconds.

 

Written by: Tazzydevil XIII
Website: http://www.frozenhaddock.co.uk