Forum Discussion
Update a variable with the current date and time
Is it possible to insert the date and time into a variable to be displayed on screen.
What I want to achieve:
To time an activity that takes place over a number of slides.
Happy to use Javascript - any help is appreciated.
40 Replies
- SinchuRaj-Community Member
use javascript and set the value to a variabl in storyline
- EdSteedsCommunity Member
Do you know the code?
- SinchuRaj-Community Member
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);DateValue is my variable in the storyline, it should be a text value
- GQuicanoCommunity Member
Thanks for sharing this. In case someone needs the year in only two digits, you can add % 100 at the end of the year line:
var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear() % 100;
var player = GetPlayer();
var newName = day + "/" + month + "/" +year
player.SetVar("DateValue", newName);
- EdSteedsCommunity Member
Thank you - you are a star.
- SinchuRaj-Community Member
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()
if (minutes
minutes = "0" + minutes
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
var CurTime = hours + ":" + minutes + " " + suffix ;
player.SetVar("TimeValue",CurTime);- JacquiDyachCommunity Member
How would you display the time in 12 hour format (instead of 24 hour)?
- SinchuRaj-Community Member
Always Welcome
- PamLeeCommunity Member
I have a question--where in Storyline do you place these codes? Do you create a separate variable for each line of code? Anyone have a screengrab of what it looks like?
- MichaelHinzeCommunity Member
Pam Lee said:
I have a question--where in Storyline do you place these codes? Do you create a separate variable for each line of code? Anyone have a screengrab of what it looks like?
You add a Excute Javascript trigger to an object, e.g. a button and then place the JavaScript inside the JavaScript window. See below a screenshot of a button that when clicked executes the date-related JavaScript listed in this thread. You can also place your code into an external file and call that function from the trigger. - MichaelHinzeCommunity Member
Michael Hinze said:
Pam Lee said:
I have a question--where in Storyline do you place these codes? Do you create a separate variable for each line of code? Anyone have a screengrab of what it looks like?
You add a Excute Javascript trigger to an object, e.g. a button and then place the JavaScript inside the JavaScript window. See below a screenshot of a button that when clicked executes the date-related JavaScript listed in this thread. You can also place your code into an external file and call that function from the trigger.
Sorry, forgot to include this link to some samples and demos that may be helpful: http://www.articulate.com/support/storyline/javascript-best-practices-and-examples Hi Pam,
I just wanted to welcome you to the E-Learning Heroes community! It looks like Michael has you covered here but if you need anything else just let us know!
Related Content
- 10 months ago
- 10 months ago
- 10 months ago
- 10 months ago