Skip to main content
claireb94986418
Participating Frequently
December 1, 2017
Question

JavaScript for specific dates and times

  • December 1, 2017
  • 1 reply
  • 1002 views

Does anyone know who to add in current dates into Captivate 9? I need to display the current date and time in the following formats on page load:

Fri, 1 Dec 17 1334 (using a 24 hour clock)

01Dec

1 Dec 17 1334

I can't seem to get the JavaScript for new Date to run correctly. Help would be appreciated. Thank you

    This topic has been closed for replies.

    1 reply

    Jeremy Shimmerman
    Participating Frequently
    December 5, 2017

    Here's what I tried and it seemed to work.

    1. Create two variables 'dt' for date, and 'tm' for time

    2. Execute the following javascript 'on Enter'

    var d = new Date();

    dt  = d.toDateString();

    tm = d.toLocaleTimeString();

    3. Create two caption boxes one with the dt variable, one with the tm variable.  

    Note that this will only load the time once. If you wanted to have a running clock, you would need to create a loop.  Hope this helps. 

    Jeremy Shimmerman
    Participating Frequently
    December 5, 2017

    Realized you shouldn't use a loop to update your clock.  Use setInterval instead.

    function getDate(){

    d = new Date();

    ti  = d.toDateString();

    dt = d.toLocaleTimeString();

    }

    setInterval(getDate, 1000);

    claireb94986418
    Participating Frequently
    December 20, 2017

    Hello and thank you so very much for your help! This one worked but the second one didn't!

    var d = new Date();

    dt  = d.toDateString();

    tm = d.toLocaleTimeString();

    I am creating a software simulation for a software that displays dates differently depending on what task you are completing. I need to show the dates separately as follows:

    DayMonth (20Dec) no spaces  (20Dec)

    Day,  Date Month YY and current time  Wed, 20 Dec 17 0948

    and then Date  month year (2 digits for the date) and 2 hours in the future from the current date. 20 Dec 17 1148

    Is there a way to modify the above to get the times to show up as above? Thank you so much!