Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Time printed is not displaying correctly.

Avatar

Level 6

Hello,

I have the following in my form, but when I print the form, the time is printing incorrectly.  It reads 4/18/2021 @ 7:6:38.  What is wrong with the script?

var oNow = new Date();
this.rawValue = (oNow.getMonth() + 1) + "/" + oNow.getDate() + "/" + oNow.getFullYear() +
" @ " + oNow.getHours() + ":" + oNow.getMinutes() + ":" + oNow.getSeconds();

 

Your help is greatly appreciated.

1 Accepted Solution

Avatar

Correct answer by
Employee

Let's assume that the formatting is wrong (single digits?). Here is how I would approach this with a DateTime field

Kosta_Prokopiu1_0-1618831990264.png

Pattern: date{MM/DD/YYYY} '@' time{HH:MM:SS}

Results in

Kosta_Prokopiu1_1-1618832031220.png

 

View solution in original post

4 Replies

Avatar

Employee
What is wrong with the printed time? Your script is basically correct but not to your expectation. Are we talking about formatting?

Avatar

Correct answer by
Employee

Let's assume that the formatting is wrong (single digits?). Here is how I would approach this with a DateTime field

Kosta_Prokopiu1_0-1618831990264.png

Pattern: date{MM/DD/YYYY} '@' time{HH:MM:SS}

Results in

Kosta_Prokopiu1_1-1618832031220.png

 

Avatar

Level 6
Thank you. So when I print the form, the date will appear? Also, Please explain the var oNow = new Date() script and why it's displaying single digits

Avatar

Employee
Yes, if you place the field and use the picture clause as shown this will also be visible on printed forms. Your script does not format the time but converts integer values to string. Hour 1 comes as 1 and converts to "1" and not "01". You could write script that adds "0"s but that is more complicated compared to using the patterns.