?
Solved

Adobe PDF Professional calculate time difference

Posted on 2011-04-21
14
Medium Priority
?
1,276 Views
Last Modified: 2012-05-11
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
Comment
Question by:Butch Smith
  • 7
  • 6
14 Comments
 
LVL 1

Author Comment

by:Butch Smith
ID: 35440617
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
 
LVL 47

Expert Comment

by:for_yan
ID: 35442112

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
 
LVL 1

Author Comment

by:Butch Smith
ID: 35442329
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

by:for_yan
ID: 35442403
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 35442498
0
 
LVL 1

Author Comment

by:Butch Smith
ID: 35443188
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
 
LVL 1

Author Comment

by:Butch Smith
ID: 35443192
YAN,

We still get an error.  
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35443205
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
 
LVL 47

Expert Comment

by:for_yan
ID: 35443286

This was compiled  - this is valid java.
Java compiler should noit write any errors - send me the deatlis
we should ceertainly understand this
0
 
LVL 1

Author Comment

by:Butch Smith
ID: 35443426
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
 
LVL 47

Expert Comment

by:for_yan
ID: 35443447
JavaScript is ablsolutely different animal.
It is not Java programming language
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35443468
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 35443483
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
 
LVL 1

Author Closing Comment

by:Butch Smith
ID: 35461628
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever come up with a need of emailing only few pages of PDF file to one of yourfriend or colleague, instead of whole Adobe file? If yes, then surely you have face problems in doing that! Read this section as I have suggested multiple solutio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question