Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript code to capture date and time from windows clock

Participant ,
Jul 24, 2017 Jul 24, 2017

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

TOPICS
Acrobat SDK and JavaScript , Windows
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2017 Jul 24, 2017

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());

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 24, 2017 Jul 24, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2017 Jul 24, 2017

Your code contains a lot of mistakes... You should spend some time studying the core JS syntax, before writing any code for Acrobat.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 25, 2017 Jul 25, 2017

But it's working

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 25, 2017 Jul 25, 2017
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines