Forum Discussion
Javascript for current time and dates
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!
- RussellKillips-Community Member
- ClaireBallan465Community Member
Thank you so very much! This is exactly what I needed.
- RussellKillips-Community Member
- LindsayMartinCommunity Member
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!
- MariaCSStaff
Hi, Erica, and welcome to E-Learning Heroes! ✨
You can test your Javascript output by publishing the .story file for the web, then opening it locally with a browser. You can also choose only to publish a single scene or slide instead:
I hope this helps!
- safirsalamCommunity Member
thanks for the explanation
- ClaireBallan465Community Member
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!
- RussellKillips-Community Member
Hello Claire,
Here is an updated project for you. I also found a mistake on my previous project. I forgot to zero pad the hours and minutes. For example 1107 was showing up as 117.
- ClaireBallan465Community Member
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 Education416-340-4800 ext. 6570
www.UHNdigital.com
[Macintosh HD:Users:lparente:AeroFS:IT3:Design:Deliverables:UHNdigital Logos:UHNdigital
- RussellKillips-Community Member
Hello Claire,
In my previous post, the project has a fourth date field that is 2 hours from the current time.
- ClaireBallan465Community Member
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 Education416-340-4800 ext. 6570
www.UHNdigital.com
[Macintosh HD:Users:lparente:AeroFS:IT3:Design:Deliverables:UHNdigital Logos:UHNdigital
- MargaretGuillorCommunity Member
I know this was a while ago. But, I am having trouble viewing the javascript and gleaning the code and picking out the what I need to just display the 24 hour clock. Can you help?
- MargaretGuillorCommunity Member
That's perfect. I removed the colon in the middle, but it works like a champ. Thanks so much!
- ChandiJayaCommunity Member
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