Javascript for current time and dates

Dec 01, 2017

Hello,

I really need some help. I want to have current dates display on columns in an elearning course that is a software simulation and I need it in different formats. Does anyone know what Javascript I would need to add that would accomplish this? I would like to display date and time in the following formats:

Fri, 1 Dec 17 1334 (using a 24 hour clock and minutes)

01Dec

1 Dec 17 1334

Help would be greatly appreciated. Thank you!

15 Replies
Claire Ballantyne

HI Russell,

Quick additional question. I would also like to show the following date in my course: 

4 Dec 17 1440 (but I need the 1440 to always be 2 hours from the current time).  This is a cut off time that is calculated based the current time.  Your help is greatly appreciated. Thank you!

Claire Ballantyne

Thank you so very much. I have another question about adding in a date. I wanted to add a date and time, but the time needs to be 2 hours from the current time and in this format: (4 Dec 17 1425). Do you know how I that can be done? Thank you!

Claire Ballantyne, CTDP
Education Specialist, UHN Digital Education

416-340-4800 ext. 6570
www.UHNdigital.com
[Macintosh HD:Users:lparente:AeroFS:IT3:Design:Deliverables:UHNdigital Logos:UHNdigital

Claire Ballantyne

Thank you! I haven't been out of storyboarding all day to check for your response. Thanks again

Claire Ballantyne, CTDP
Education Specialist, UHN Digital Education

416-340-4800 ext. 6570
www.UHNdigital.com
[Macintosh HD:Users:lparente:AeroFS:IT3:Design:Deliverables:UHNdigital Logos:UHNdigital

Lindsay Martin

Has anyone experienced glitches with their date/time variables? I have a project (same as Claire's above) with numerous date/time variables and it works sometimes so I believe the javascript/triggers/variables are accurate. However, they stop working sometimes.. seemingly random, but wondering if the community has any advice. A few pieces of additional info: 

-the storyline project file is really large with a lot of project variables.. could that be effecting it?

-the variables were previously numbered (ie. Date1, Date2, etc) and SL seemed to be renaming them to higher numbers, so we switched to letters (ie. DateA, DateB, etc) but no luck

-this is tested and posted on a website so it is not the previously mentioned viewing problem

I can't attach the full project for proprietary reasons, but here are the variables, an example slide of trigger, and the javascript. 

Thank you in advance! 

Chandi Jaya

Hi,

I have a Storyline3 project which needs to display the system time, always updating.

I used the following code, but it didn't work.

function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();

// add a zero in front of numbers<10
m = checkTime(m);
s = checkTime(s);

var p=GetPlayer();
p.SetVar("h",h);

var q=GetPlayer();
q.SetVar("m",m);

var r=GetPlayer();
r.SetVar("s",s);

var t = setTimeout(function(){ startTime() }, 1000);
}

function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}

 Does anyone know the exact code for this?

Chandi
Reply
 Quote