Need some help with Current Time issue in html5

Hi everyone - I'm hoping someone can help me with a little problem I'm having with some JavaScript code I'm using to retrieve the current date and time in my storyline file.

The issue I am having is with the display of the minutes. Everything works fine when viewing the flash version of the output but in html5 the leading zero does not display when the minutes are under 10.  So for example, 7:01 am looks like 7:1

I've attached the slide if anyone wants to take a look.

7 Replies
Jiri Mihal

Nancy Woinoski said:

Hi everyone - I'm hoping someone can help me with a little problem I'm having with some JavaScript code I'm using to retrieve the current date and time in my storyline file.

The issue I am having is with the display of the minutes. Everything works fine when viewing the flash version of the output but in html5 the leading zero does not display when the minutes are under 10.  So for example, 7:01 am looks like 7:1

I've attached the slide if anyone wants to take a look.

Hi Nancy,

just use following function in JavaScript to add zeros before numbers less than 10.

// add zeros to numbers, that are only one char length

function padlength(what){

   var output=(what.toString().length==1)? "0"+what : what;

   return output;

}

// init new date object

var serverdate=new Date();

// get minutes and seconds with leading zeros

var minutes = serverdate.getMinutes();

var seconds = serverdate.getSeconds();

-------------------------------------------------------------------------------------

Nice guide to JS Date object: http://www.w3schools.com/jsref/jsref_obj_date.asp

You can see it in action here: http://www.timeutils.com/current-time

I hope it helps.

Jiri