Javascript code to capture date and time from windows clock
Copy link to clipboard
Copied
Good afternoon people,
I would like to create a button where a person clicks, appears in a textbox, the date and time of the Windows clock. it is possible?
Best regards
Berg
Copy link to clipboard
Copied
Certainly. Use this code as the button's MouseUp script (adjust the field name and date format, of course):
this.getField("CurrentTime").value = util.printd("mm/dd/yyyy HH:MM", new Date());
Copy link to clipboard
Copied
Thanks for the help, I got it.
I am using this code to generate a name in a textbox, based on their respective names. The name that appears to me in the textbox is: GPDS_ContractName_ Date and Time. I use this to generate the default file name for me. I would like to insert below a
Var v1 = "GPDS_" + getField ("CONTRACT NAME"). ValueAsString + "_" + getField ("TIME") valueAsString
Var v2 = v1.replace ("/", "");
Var v3 = v2.replace ("/", "");
Var v4 = v3.replace (":", "");
GetField ("FILE NAME"). Value = v4;
Regards,
Berg
Copy link to clipboard
Copied
Your code contains a lot of mistakes... You should spend some time studying the core JS syntax, before writing any code for Acrobat.
Copy link to clipboard
Copied
But it's working
Copy link to clipboard
Copied
But how are you populating the time field. If you add a document level script like
this.getField("Time").value = util.printd("mm/dd/yyyy HH:MM", new Date());
The time field will be automatically populated with the system time when the PDF is opened. It is also possible when using the Date object to easily pull the year, month, date, hour, and minutes form a valid date.
If the user is entering the date and time how are you validating that the entered data is correct?
It is also possible that the name could contain the "/" or ":" and then your script might not properly work.

