Forum Discussion
Update a variable with the current date and time
I had issues getting this code to work, so I (not having any Javascripting experience) tinkered around with it until it did. Here is the code that does work which I have setup via two javascript triggers:
Trigger 1
var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear();
var player = GetPlayer();
var newName = month + "/" + day + "/" +year
player.SetVar("DateValue", newName);
Trigger 2
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var seconds = currentTime.getSeconds()
if (hours <12)
var suffix = "AM";
if (hours >= 12)
var suffix = "PM";
var CurTime = hours+":"+minutes+":"+seconds+" "+suffix;
player.SetVar("TimeValue",CurTime);
To get this to work in Storyline, first setup two text variables, "DateValue", and "TimeValue". Then on your slide or master slide, setup a text box or object and then insert two references for DateValue and TimeValue. I simply set the triggers to execute Javascript when timeline starts.
You can modify the code easily by modifying the varCurTime, or var newName lines. I really am not sure what that nested statement in the time code was about in the original code but I could not get it to work.
Test file attached.
- ElainePretty-1511 years agoCommunity Member
Thanks David! works perfectly
Related Content
- 10 months ago
- 10 months ago
- 10 months ago