Forum Discussion
Great, thanks!
- Jonathan_Hill5 hours agoSuper Hero
Actually, just found the code in my cloud drive.
Try this.
You'll need to create three TEXT variables to receive the data, named vTime, vDateShort and vDateLong.
Trigger the code to run when your timeline starts.
// Function to update the time and date variables
function updateTimeAndDate() {
// Get the current time and date
var now = new Date();// Format the time in 24-hour format (HH:MM)
var hours = now.getHours().toString().padStart(2, '0');
var minutes = now.getMinutes().toString().padStart(2, '0');
var vTime = hours + ":" + minutes;// Format the short date (MM/DD/YY)
var month = (now.getMonth() + 1).toString().padStart(2, '0');
var day = now.getDate().toString().padStart(2, '0');
var year = now.getFullYear().toString().slice(-2);
var vDateShort = month + "/" + day + "/" + year;// Format the long date (Month DD, YYYY)
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
var vDateLong = monthNames[now.getMonth()] + " " + day + ", " + now.getFullYear();// Update the text variables in Storyline
try {
var player = GetPlayer();
if (player && typeof player.SetVar === "function") {
player.SetVar("vTime", vTime);
player.SetVar("vDateShort", vDateShort);
player.SetVar("vDateLong", vDateLong);
console.log("Time set to: " + vTime);
console.log("Short Date set to: " + vDateShort);
console.log("Long Date set to: " + vDateLong);
} else {
console.error("GetPlayer() or SetVar function not available");
}
} catch (error) {
console.error("Error setting variables:", error);
}
}// Call the updateTimeAndDate function once
updateTimeAndDate();