Date Methods

Use Primavera Cloud supported date methods to manipulate date data.

Refer to the official Java documentation for more information on each method.

Notes:

Date Methods

Method Signature

Description

Parameters

Example

Date.after(Date when)

Returns a Boolean value indicating whether the Date calling the after method occurs after the Date passed as an argument.

Date when - Date to compare against.

def now = new Date();

def later = new Date("2999 Nov 27");

now.after(later); //returns false

later.after(now); //returns true

Date.before(Date when)

Returns a Boolean value indicating whether the Date calling the before method occurs before the Date passed as an argument.

Date when - Date to compare against.

def now = new Date();

def later = new Date("2999 Nov 27");

now.before(later); //returns true

later.before(now); //returns false

Date.compareTo(Date anotherDate)

Compares the value of the Date passed as an argument to the Date calling the compareTo method. Returns a 0 if the dates are equal, less than 0 if the Date calling the compareTo method occurs before the argument, and greater than 0 if the Date calling the compareTo method occurs after the argument.

Date anotherDate - Date to compare against.

def now = new Date();

def then = now;

def later = new Date("2999 Nov 27");

now.compareTo(then); //returns 0

now.compareTo(later); //returns -1

Date.equals(Date anotherDate)

Checks if the Date calling the equals method is equivalent to the Date passed as an argument. Dates are equivalent if they represent the same point in time to the millisecond. Returns true if the Dates are equal and returns false otherwise.

Date anotherDate - Date value to compare against.

def now = new Date();

def then = now;

def later = new Date("2999 Nov 27");

now.equals(then); //returns true

now.equals(later); //returns false

Date.getDate()

Returns a value between 1 and 31 representing the day of the Date calling the getDate method.

No method parameters.

def now = new Date();

now.getDate(); //returns 20

Date.getTime()

Returns the value of the Date calling the getTime method represented as the number of milliseconds since January 1, 1970, 00:00:00 GMT.

No method parameters.

def now = new Date();

now.getTime(); //returns 1490039162479

Date.hashCode()

Returns a hash code representing the Date calling the hashCode method.

No method parameters.

def now = new Date();

now.hashCode(); //returns a hash code value representing this date, for example -313684330

Additional Date Methods

Method Signature

Description

Parameters

Example

Date.getHours()

Returns a value between 0 and 23 representing the hours of the Date calling this method.

No method parameters.

x = new Date(0;

x.getHours(); //returns a value similar to 15

Date.getMinutes()

Returns a value between 0 and 59 representing the minutes of the Date calling this method.

No method parameters.

x = new Date();

x.getMinutes(); //returns a value similar to 41

Date.getSeconds()

Returns a value between 0 and 61 representing the minutes of the Date calling this method.

No method parameters.

x = new Date();
x.getSeconds(); //returns a value similar to 32

Date.getTimezoneOffset()

Returns the offset between the Date calling this method and UTC represented in minutes.

No method parameters.

x = new Date();
x.getTimezoneOffset(); //returns a value similar to 0

Date.getYear()

Returns the result of subtracting 1900 from the year contained in the Date calling this method.

No method parameters.

x = new Date();

x.getYear(); //returns a value similar to 117

Date.parse(String string)

Returns the result of converting the String passed as an argument to a Date value.

String string - String representation of a date.

Date.parse("3/4/17"); //returns 1488585600000

Date.toGMTString()

Returns a String representing the Date calling this method in GMT format.

No method parameters.

x = new Date();

x.toGMTString(); //returns "17 May 2017 15:41:04 GMT"

Date.toLocaleString()

Returns a String representing the Date calling this method in an implementation independent form.

No method parameters.

x = new Date();

x.toLocaleString(); //returns a value similar to "May 17, 2017 3:41:04 PM"

Date.toString()

Returns a String representing the Date calling this method in the form dow mon dd hh:mm:ss zzz yyyy.

No method parameters.

x = new Date();

x.toString(); //returns a value similar to "Wed May 17 15:41:04 UTC 2017"



Last Published Tuesday, May 21, 2024