Adobe 12001196 - Acrobat - Mac Manual page 80

Javascript
Hide thumbs Also See for 12001196 - Acrobat - Mac:
Table of Contents

Advertisement

A Short Acrobat JavaScript FAQ
A
How do I use date objects?
representation. Internally, JavaScript dates are stored as the number of milliseconds (one
thousand milliseconds is one whole second) since a fixed date and time. This number can
be retrieved through the valueOf method of the Date object. The Date constructor allows
the construction of a new date from this number.
/* Example of date arithmetic. */
/* Create a Date object with a definite date. */
var d1 = util.scand("mm/dd/yy", "4/11/76");
/* Create a date object containing the current date. */
var d2 = new Date();
/* Number of seconds difference. */
var diff = (d2.valueOf() - d1.valueOf()) / 1000;
/* Print some interesting stuff to the console. */
console.println("It has been "
console.println("It has been "
console.println("It has been "
console.println("It has been "
console.println("It has been "
The output of this script would look something like:
It has been 718329600 seconds since 4/11/1976
It has been 11972160 minutes since 4/11/1976
It has been 199536 hours since 4/11/1976
It has been 8314 days since 4/11/1976
It has been 22.7780821917808 years since 4/11/1976
The following example shows the addition of dates.
/* Example of date arithmetic. */
/* Create a date object containing the current date. */
var d1 = new Date();
/* num contains the numeric representation of the current date. */
var num = d1.valueOf();
/* Add thirteen days to today's date, in milliseconds. */
/* 1000 ms/sec, 60 sec/min, 60 min/hour, 24 hours/day, 13 days */
num += 1000 * 60 * 60 * 24 * 13;
/* Create our new date, 13 days ahead of the current date. */
var d2 = new Date(num);
/* Print out the current date and our new date using util.printd */
console.println("It is currently: "
console.println("In 13 days, it will be: "
The output of this script would look something like:
It is currently: 01/15/1999
In 13 days, it will be: 01/28/1999
80
+ diff + " seconds since 4/11/1976");
+ diff / 60 + " minutes since 4/11/1976");
+ (diff / 60) / 60 + " hours since 4/11/1976");
+ ((diff / 60) / 60) / 24 + " days since 4/11/1976");
+ (((diff / 60) / 60) / 24) / 365 + " years since 4/11/1976");
+ util.printd("mm/dd/yyyy", d1));
+ util.printd("mm/dd/yyyy", d2));
Acrobat JavaScript Scripting Guide

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Acrobat 6.0

Table of Contents