Using {timestamp} in custom js

Forums Classic DFFS Using {timestamp} in custom js

Tagged: 

Viewing 4 reply threads
  • Author
    Posts
    • #19594
      Jon Mortimer
      Participant

      Hi All,

      I apologize in advance if this is a newbie question. I’ve checked the forum and just could not find anything. Is there a way to use the {timestamp} variable in the custom js? I have custom js that adds a date/time (format: Sat, Feb 3 08:23:56 EST 2018) but it is scrambled and does not match the formatting used in the {timestamp} variable (Saturday, February 3, 2018 08:23:56 EST) and want them to be consistent.

    • #19596
      Alexander Bautz
      Keymaster

      You can use this snippet to insert a timestamp in Custom JS:

      spjs.dffs.buildValStr("{timestamp[dd.MM.yyyy hh:mm:ss]}");
      // Outputs 03.02.2018 16:27:06

      Alexander

    • #19598
      Jon Mortimer
      Participant

      How do I make this output as: Saturday, February 3, 2018 08:23:56 EST

      I tried adjusting the variables (as I would in Javascript) but it doesn’t seem to follow the same format?? Again, sorry for the novice questions and appreciate what you’ve done with the software and the great support.

    • #19600
      Alexander Bautz
      Keymaster

      The DFFS method only supports numeric values for day and month. To get this format you must either write a custom function or use the date methods in the browser (behaves a bit different in different browsers so please test it in all relevant browsers). Have you tried the built in method:

      var date = new Date();
      var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second:'2-digit', timeZoneName:"short"};
      console.log(date.toLocaleDateString('en-US', options));

      Please note that this does not work properly in Internet Explorer

      You find more info here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

      Alexander

    • #19604
      Jon Mortimer
      Participant

      Thank you for pointing me in the right direction, I figured it out. I don’t think I was clear in my original email.

      In any event, I changed what you sent to just spjs.dffs.buildValStr(“{timestamp}”); and this provided me exactly what I needed, no need to modify the formatting at all. It outputs as Saturday, February 3, 2018 08:23:56 EST.

      Thanks!

Viewing 4 reply threads
  • You must be logged in to reply to this topic.