Highlighted

Adding 2 hours to current time

New Here ,
Jul 23, 2020

Copy link to clipboard

Copied

Hello all,

Im sorry if this has been asked, i have been through all the help docs and through google.  i am new to Acrobat DC and am trying to create a JavaScript that adds 2 hours to the current time.  I dont need the entire date, only the hours.  ie. i save my form and it automatically says the time in "arrival" 2 hours from the system time.  I am able to get the current time to populate with:

 

var f = this.getField("arrival"); f.value = util.printd("HH:MM", new Date());

 

and tried adding the variables i could find to add 2 hours two it. I tried using the adding the 5 days format i found in the community and tweaking it to my need to no avail:

 

var f = this.getField("arrival");var twohours = .83 * 24 * 60 * 60 * 1000;var theNewDate = new Date (finalTime); f.value = util.printd("HH:MM", new Date());

 

can anyone help?

Topics

Acrobat SDK and JavaScript

Views

43

Likes

Translate

Translate

Report

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

Adding 2 hours to current time

New Here ,
Jul 23, 2020

Copy link to clipboard

Copied

Hello all,

Im sorry if this has been asked, i have been through all the help docs and through google.  i am new to Acrobat DC and am trying to create a JavaScript that adds 2 hours to the current time.  I dont need the entire date, only the hours.  ie. i save my form and it automatically says the time in "arrival" 2 hours from the system time.  I am able to get the current time to populate with:

 

var f = this.getField("arrival"); f.value = util.printd("HH:MM", new Date());

 

and tried adding the variables i could find to add 2 hours two it. I tried using the adding the 5 days format i found in the community and tweaking it to my need to no avail:

 

var f = this.getField("arrival");var twohours = .83 * 24 * 60 * 60 * 1000;var theNewDate = new Date (finalTime); f.value = util.printd("HH:MM", new Date());

 

can anyone help?

Topics

Acrobat SDK and JavaScript

Views

44

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Jul 23, 2020

Copy link to clipboard

Copied

You set twohours then don't do anything with the value. Take a closer look at the examples you are trying to adapt. You need to understand what you use. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 23, 2020

Copy link to clipboard

Copied

It is possible to add 2 hours to the current time of a given time of day if the result does not cross the end of the day or the tme in which there is a change for Daylight Savinngs Time. One can split the time format inot hours and minutes and then adjust the value for the hours.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jul 23, 2020

Copy link to clipboard

Copied

Use this:

 

var f = this.getField("arrival");
var now = new Date();
var twohours = 2 * 60 * 60 * 1000;
var theNewDate = new Date(now.getTime()+twohours); 
f.value = util.printd("HH:MM", theNewDate);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
cwl1983 LATEST
New Here ,
Jul 23, 2020

Copy link to clipboard

Copied

THANK YOU!!! i have been trying every possible combo of variables i could think of or find.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...