• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1408
  • Last Modified:

Adobe PDF Professional calculate time difference

We created a form in PDF professional and have the user input two time fields as HH:MM:SS.  We have another field that is to calculate the time difference between the two fields.  We tried a simple field1 - field2.  This works only if the format is not in time, but unfortunately it is.

Any ideas.  The two fields that are to be calculated are (dispatchtime) and (onscenetime)

Thanks
0
Butch Smith
Asked:
Butch Smith
  • 7
  • 6
1 Solution
 
Butch SmithAuthor Commented:
Some research suggests we have to create a java script that converts the time into seconds, does the calculation and then converts it back.  Not sure how to do this if in fact we need to.
0
 
for_yanCommented:

Don't know how you could apply it to Adobe, but this is java snippet
which should giive you difference in time in seconds in case you need it
(hours are on 24 scale - 0-23):


String field1 = "10:15:00";
String field2 = "10:30:00";

SimpleDateFormat ff = new SimpleDateFormat("HH:mm:ss");
java.util.Date d1 = ff.parse(field1, new ParsePosition(0));
java.util.Date  d2 = ff.parse(field2, new ParsePosition(0));

long time_sec = (d2.getTime()-d1.getTime())/1000L;

System.out.println("Time: " + time_sec);
0
 
Butch SmithAuthor Commented:
In java editor we get an error that highlights the String field2 = "10:30:00";

says:  syntaxerror: missing ; before statement 1 : at line 2

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
for_yanCommented:
Well, don't know waht you mean by Java editor;
though this is a perfectly valid java statement,
this is all just a snippet - in java it would normally be part of the class, maybe that's
what your editor is complaining about  - as it is lacking  the context.
The context should depend on how you can attach it to your problem with PDF .

Maybe this is what your java editor can accept, but we really need to
know how to apply it to your Adobe form
import java.text.ParsePosition;
import java.text.SimpleDateFormat;

public class TimeDifference {

public static void main(String [] args){

String field1 = "10:15:00";
String field2 = "10:30:00";

SimpleDateFormat ff = new SimpleDateFormat("HH:mm:ss");
java.util.Date d1 = ff.parse(field1, new ParsePosition(0));
java.util.Date  d2 = ff.parse(field2, new ParsePosition(0));

long time_sec = (d2.getTime()-d1.getTime())/1000L;

System.out.println("Time: " + time_sec);


}

}

Open in new window


0
 
Butch SmithAuthor Commented:
CEHJ  

I see your link, but have a hard time understanding where to place my two time fields.  My first time field is called "dispatchtime"   and my second is called "onscenetime"

Thanks
0
 
Butch SmithAuthor Commented:
YAN,

We still get an error.  
0
 
for_yanCommented:
What are you using?
This my code compiles in java IDE without any problems.
Are you using javac to compile, if you are using IDE, then what IDE?
0
 
for_yanCommented:

This was compiled  - this is valid java.
Java compiler should noit write any errors - send me the deatlis
we should ceertainly understand this
0
 
Butch SmithAuthor Commented:
This is what adobe says about java script.  Again this is creating a adobe acrobat professional form

Based on JavaScript version 1.5 of ISO-16262 (formerly known as ECMAScript), JavaScript in Adobe Acrobat software implements objects, methods, and properties that enable you to manipulate PDF files, produce database-driven PDF files, modify the appearance of PDF files, and much more. You can tie Acrobat JavaScript code to a specific PDF document, a page, field, or button within that document, or a field or button within the PDF file, and even to a user action.
0
 
for_yanCommented:
JavaScript is ablsolutely different animal.
It is not Java programming language
0
 
for_yanCommented:
I gues waht you need from there is:

function HMStoSec1(T) { // h:m:s
  var A = T.split(/\D+/) ; return (A[0]*60 + +A[1])*60 + +A[2] }

var time1 = HMStoSec1("10:00:00");
var time2 = HMStoSec1("12:05:00");
var diff = time2 - time1;
document.write(diff);

0
 
Butch SmithAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now