Home › Forums › Classic DFFS › Using {timestamp} in custom js
Tagged: timestamp
- This topic has 4 replies, 2 voices, and was last updated 6 years, 10 months ago by Jon Mortimer.
-
AuthorPosts
-
-
February 3, 2018 at 14:27 #19594
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.
-
February 3, 2018 at 16:27 #19596
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
-
February 3, 2018 at 16:50 #19598
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.
-
February 3, 2018 at 22:05 #19600
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
-
February 4, 2018 at 15:34 #19604
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!
-
-
AuthorPosts
- You must be logged in to reply to this topic.