Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Time printed is not displaying correctly.

islandgirl23
Level 4
Level 4

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
Kosta_Prokopiu1
Correct answer by
Employee
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
Kosta_Prokopiu1
Employee
Employee
What is wrong with the printed time? Your script is basically correct but not to your expectation. Are we talking about formatting?
Kosta_Prokopiu1
Correct answer by
Employee
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

islandgirl23
Level 4
Level 4
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
Kosta_Prokopiu1
Employee
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.