I'm not sure if David is still subscribed here as I saw he also didn't answer Jacqui's similar question. I don't know much (or anything really!) about Javascript code, so I hope someone here in the community can pop in to assist. You could also try using the "contact me" button on a ELH users' profile to reach out to them directly for advice! Best of luck with your project!
I think this simplified script here should do the trick;
var currentDate = new Date(); var day = currentDate.getDate(); var month = currentDate.getMonth() + 1; var year = currentDate.getFullYear(); var player = GetPlayer(); var newName = day + "/" + month + "/" +year player.SetVar("DateValue", newName); var currentTime = new Date(); var hours = currentTime.getHours(); var minutes = currentTime.getMinutes(); var CurTime = hours + ":" + minutes; player.SetVar("TimeValue",CurTime);
Von: E-Learning Heroes [mailto:heroes@articulate.com]
Gesendet: Donnerstag, 8. November 2018 17:24
An: Martin Volckart
Betreff: Reply to Update a variable with the current date and time
Just an FYI - It looks like your email signature came through when you replied via email. You can remove that if needed by clicking ‘Edit’ beneath your response. Here’s a quick Peek video if you need help.
I just realized my earlier script suggestion would not account for hours and minutes< 10. They would be shown like "9:9". See attached a quick update that fixes this issue to show the hours and minutes always with two digits, e.g. "09:09". Here is the published example.
This is a great thread, just what I need but I cannot get the DateTime_Test.story file from David above to work. The date works, but not the time. See attachment. I didn't make any changes except downloading the .story file and upgrading it to SL 360 and publishing and uploading to Canvas LMS. Any suggestions? I really need a date and time stamped on the results slide, right down to the seconds like this example shows. I'm not super good at JavaScript, but I do understand the need to create variables and the basics of how this should work. For instance, I have a variable that calls up the user's name from Canvas, and that works . . . . I've spent a lot more time than I expected looking at other threads, and help would be appreciated!
It is working beautifully. However, there are a few places where the learner completes a process and I want to take a timestamp of when they push the hotspot to start the process. So if they click the hotspot at 1:00 pm, it will show 1:00 pm on all the following slides. Is there a way to do this? I can't use the reference to the existing variable because the time changes. So I am assuming I need a new javascript for the timestamp. Any help would be much appreciated! (Note - I don't know how to write code, I just know how to copy and paste! Be gentle!) LOL
39 Replies
How would you display the time in 12 hour format (instead of 24 hour)?
Hello David,
could you tell me how the time code works for Germany? We Count 24 Hours a day without AM or PM.
Thank you very much.
Hi Martin,
I'm not sure if David is still subscribed here as I saw he also didn't answer Jacqui's similar question. I don't know much (or anything really!) about Javascript code, so I hope someone here in the community can pop in to assist. You could also try using the "contact me" button on a ELH users' profile to reach out to them directly for advice! Best of luck with your project!
I think this simplified script here should do the trick;
var currentDate = new Date();
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
var player = GetPlayer();
var newName = day + "/" + month + "/" +year
player.SetVar("DateValue", newName);
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var CurTime = hours + ":" + minutes;
player.SetVar("TimeValue",CurTime);
Hello Michael,
perfect! Thanks a lot for your invaluable help.
Best regards
Martin
Von: E-Learning Heroes [mailto:heroes@articulate.com]
Gesendet: Donnerstag, 8. November 2018 17:24
An: Martin Volckart
Betreff: Reply to Update a variable with the current date and time
Glad that worked, Martin!
Just an FYI - It looks like your email signature came through when you replied via email. You can remove that if needed by clicking ‘Edit’ beneath your response. Here’s a quick Peek video if you need help.
I just realized my earlier script suggestion would not account for hours and minutes< 10. They would be shown like "9:9". See attached a quick update that fixes this issue to show the hours and minutes always with two digits, e.g. "09:09". Here is the published example.
Hi Michael,
could you post the code. I use SL3 and cannot open the project file.
Thanks again
Martin
Hi Martin,
No worries, I opened the file shared above and switched from the Modern Player to Classic Player and you can open this file in SL3 now :)
This is a great thread, just what I need but I cannot get the DateTime_Test.story file from David above to work. The date works, but not the time. See attachment. I didn't make any changes except downloading the .story file and upgrading it to SL 360 and publishing and uploading to Canvas LMS. Any suggestions? I really need a date and time stamped on the results slide, right down to the seconds like this example shows. I'm not super good at JavaScript, but I do understand the need to create variables and the basics of how this should work. For instance, I have a variable that calls up the user's name from Canvas, and that works . . . . I've spent a lot more time than I expected looking at other threads, and help would be appreciated!
hi everyone,
any chance to get hep on how to delay quiz attempts with x hours?
more exactly I am looking to add x hours between the current date/time (of the 1st attempt) and the next attempt.
thank you,
Ionut
hi Michael,
since you rock on JavaScript, do you know how to add x hours between quiz attempts?
thank you!
Hi Ionut,
You can also feel free to reach out to Michael directly by clicking on his profile and using the Contact Me button!
Not sure if anyone still following this thread, I did reach out to some people individually.
Here is my question:
I am using the following javascript to display the learner's current time in my course.
______________________
var player = GetPlayer();
function date_time() {
var date = new Date();
var am_pm = "AM";
var hour = date.getHours();
if(hour>=12){
am_pm = "PM";
}
if(hour>12){
hour = hour - 12;
}
if(hour<10){
hour = "0"+hour;
}
var minute = date.getMinutes();
if (minute<10){
minute = "0"+minute;
}
player.SetVar("12Hour", hour+":"+minute+" "+am_pm);
}
setInterval(date_time,500);
_________________________________
It is working beautifully. However, there are a few places where the learner completes a process and I want to take a timestamp of when they push the hotspot to start the process. So if they click the hotspot at 1:00 pm, it will show 1:00 pm on all the following slides. Is there a way to do this? I can't use the reference to the existing variable because the time changes. So I am assuming I need a new javascript for the timestamp. Any help would be much appreciated! (Note - I don't know how to write code, I just know how to copy and paste! Be gentle!) LOL
Thank you!