Console Webservice API

DateUtil

Other API in Package

Console

Console System

Internal Console

The class DateUtil provides utility methods for manipulating and parsing Date objects

Method Summary
Date addDays(Date date, int days)

Returns a new Date offset in days from the given date.

Date addHours(Date date, int hours)

Returns a new Date offset in hours from the given date.

Date addMinutes(Date date, int minutes)

Returns a new Date offset in minutes from the given date.

Date addMonths(Date date, int months)

Returns a new Date offset in months from the given date.

Date addSeconds(Date date, int seconds)

Returns a new Date offset in seconds from the given date.

Date addYears(Date date, int years)

Returns a new Date offset in years from the given date.

Date calcDate(int year, int monthOfYear, int weekOfMonth, int dayOfWeek)

Returns the date of the [week] [day] of the given month and year. For example, (2019,3,2,1) will return the 2nd Sunday of March 2019. This may return null if no date exists with the criteria.

Date createDate()

Creates a date with the current time on the server

int getAge(Date date)

Returns the age in (in years) from the given date. If the date is in the future, this will return a negative number.

int getAgeInDays(Date startDate, Date endDate)

Returns the number of full days between the specified dates. If startDate is after endDate, return this as a negative number.

int getAgeInHours(Date startDate, Date endDate)

Returns the number of full hours between the specified dates. If startDate is after endDate, return this as a negative number.

long getAgeInMinutes(Date startDate, Date endDate)

Returns the number of full minutes between the specified dates. If startDate is after endDate, return this as a negative number.

int getAgeInMonths(Date startDate, Date endDate)

Returns the number of full months between the specified dates. If startDate is after endDate, return this as a negative number.

long getAgeInSeconds(Date startDate, Date endDate)

Returns the number of full seconds between the specified dates. If startDate is after endDate, return this as a negative number.

int getAgeInYears(Date startDate, Date endDate)

Returns the number of full years between the specified dates. If startDate is after endDate, return this as a negative number.

PacketDataList getCalendar(int year)

Returns a calendar datalist for the given year.

Data getDateDiff(Date startDate, Date endDate)

Returns a Data object containing fields: years, months, days, hours, minutes, seconds with values representing the time between the two dates. All values are positive.

Date getDateNextMonth(int dayOfMonth)

Returns a new Date with the given day of the month next month from now.

Date getDateThisMonth(int dayOfMonth)

Returns a new Date with the given day of this month.

int getDay(Date date)

Returns the day of the month (1-31) of the given date.

int getDayOrdinal(Date date)

Returns the Nth day of this date. If it is the 1st Thursday, this will return 1. If it is the 3rd Friday, this will return 3.

Date getEndOfDay(Date date)

Returns a new Date which is the beginning of the given day (the time will be 11:59:59 PM).

Date getEndOfMonth(Date date)

Returns a new Date for the last day of the month of the given date.

Date getEndOfYear(Date date)

Returns a new Date for the last day of the year of the given date.

int getMonth(Date date)

Returns the month of the year (1-12) of the given date.

Date getStartOfDay(Date date)

Returns a new Date which is the beginning of the given day (the time will be 12:00:00 AM).

Date getStartOfMonth(Date date)

Returns a new Date for the first day of the month of the given date.

Date getStartOfYear(Date date)

Returns a new Date for the first day of the year of the given date.

int getWeekOfMonth(Date date)

Returns the week of the month for the given date.

int getWeekOfYear(Date date)

Returns the week of the year for the given date.

int getYear(Date date)

Returns the year of the given date.

boolean isDate(Date date1, Date date2)

Returns true if the two dates have the same day, month, and year

boolean isTime(Date date, int startHour, int startMinute, int endHour, int endMinute)

Returns true if the date is within the 24 hour start and end times.

Date nextMonth(Date date)

Adds a month to the date and returns the date with the same day of week and week of month. Returns null if the operation is not possible.

Date parseComplexDate(String date)

Creates a date from the given string. Format can be almost any valid date (e.g. Mar. 3rd, 1956 or 5/5/2008). Returns null if the date cannot be parsed.

Date parseDate(String date)

Creates a date from the given string. Format should be MM-dd-yyyy or MM/dd/yyyy

Date parseDate(String date, String pattern)

Creates a date from the given string. Format should adhere to pattern. See java.text.SimpleDateFormat API documentation for more information about possible patterns.

Date parseDatetime(String date)

Creates a date from the given string. String can be either integer value in milliseconds or in format MM-dd-yyyy or MM/dd/yyyy

Method Detail


Date addDays(Date date, int days)

Returns a new Date offset in days from the given date.

Parameters:

  • Date   date Required parameter.
  • int   days Required parameter.

Returns:  Date

Since: 06-27-2007

top

Date addHours(Date date, int hours)

Returns a new Date offset in hours from the given date.

Parameters:

  • Date   date Required parameter.
  • int   hours Required parameter.

Returns:  Date

Since: 06-27-2007

top

Date addMinutes(Date date, int minutes)

Returns a new Date offset in minutes from the given date.

Parameters:

  • Date   date Required parameter.
  • int   minutes Required parameter.

Returns:  Date

Since: 05-29-2009

top

Date addMonths(Date date, int months)

Returns a new Date offset in months from the given date.

Parameters:

  • Date   date Required parameter.
  • int   months Required parameter.

Returns:  Date

Since: 06-27-2007

top

Date addSeconds(Date date, int seconds)

Returns a new Date offset in seconds from the given date.

Parameters:

  • Date   date Required parameter.
  • int   seconds Required parameter.

Returns:  Date

Since: 12-21-2012

top

Date addYears(Date date, int years)

Returns a new Date offset in years from the given date.

Parameters:

  • Date   date Required parameter.
  • int   years Required parameter.

Returns:  Date

Since: 06-27-2007

top

Date calcDate(int year, int monthOfYear, int weekOfMonth, int dayOfWeek)

Returns the date of the [week] [day] of the given month and year. For example, (2019,3,2,1) will return the 2nd Sunday of March 2019. This may return null if no date exists with the criteria.

Parameters:

  • int   year  - This should be a 4 digit year, e.g. 2019 not 19.. Required parameter.
  • int   monthOfYear  - Should be 1-12 where 1 is January. Required parameter. Maximum allowed size of parameter: 12
  • int   weekOfMonth  - Should be 1-5, typically 1-4. Required parameter. Maximum allowed size of parameter: 5
  • int   dayOfWeek  - Should be 1-7, where 1 is Sunday and 7 is Saturday. Required parameter. Maximum allowed size of parameter: 7

Returns:  Date

Since: 03-08-2019

top

Date createDate()

Creates a date with the current time on the server

Returns:  Date

Since: 06-27-2007

top

int getAge(Date date)

Returns the age in (in years) from the given date. If the date is in the future, this will return a negative number.

Parameters:

  • Date   date Required parameter.

Returns:  int

Since: 06-27-2007

top

int getAgeInDays(Date startDate, Date endDate)

Returns the number of full days between the specified dates. If startDate is after endDate, return this as a negative number.

Parameters:

  • Date   startDate Required parameter.
  • Date   endDate Required parameter.

Returns:  int

Since: 09-04-2008

top

int getAgeInHours(Date startDate, Date endDate)

Returns the number of full hours between the specified dates. If startDate is after endDate, return this as a negative number.

Parameters:

  • Date   startDate Required parameter.
  • Date   endDate Required parameter.

Returns:  int

Since: 09-30-2013

top

long getAgeInMinutes(Date startDate, Date endDate)

Returns the number of full minutes between the specified dates. If startDate is after endDate, return this as a negative number.

Parameters:

  • Date   startDate Required parameter.
  • Date   endDate Required parameter.

Returns:  long

Since: 09-30-2013

top

int getAgeInMonths(Date startDate, Date endDate)

Returns the number of full months between the specified dates. If startDate is after endDate, return this as a negative number.

Parameters:

  • Date   startDate Required parameter.
  • Date   endDate Required parameter.

Returns:  int

Since: 09-04-2008

top

long getAgeInSeconds(Date startDate, Date endDate)

Returns the number of full seconds between the specified dates. If startDate is after endDate, return this as a negative number.

Parameters:

  • Date   startDate Required parameter.
  • Date   endDate Required parameter.

Returns:  long

Since: 09-30-2013

top

int getAgeInYears(Date startDate, Date endDate)

Returns the number of full years between the specified dates. If startDate is after endDate, return this as a negative number.

Parameters:

  • Date   startDate Required parameter.
  • Date   endDate Required parameter.

Returns:  int

Since: 09-04-2008

top

PacketDataList getCalendar(int year)

Returns a calendar datalist for the given year.

Parameters:

  • int   year Required parameter.

Returns:  PacketDataList


DataList Name: calendar
DataList Fields: month, moy, year, week, sun, mon, tue, wed, thu, fri, sat

Since: 01-10-2023

top

Data getDateDiff(Date startDate, Date endDate)

Returns a Data object containing fields: years, months, days, hours, minutes, seconds with values representing the time between the two dates. All values are positive.

Parameters:

  • Date   startDate Required parameter.
  • Date   endDate Required parameter.

Returns:  Data

Since: 09-30-2013

top

Date getDateNextMonth(int dayOfMonth)

Returns a new Date with the given day of the month next month from now.

Parameters:

  • int   dayOfMonth Required parameter.

Returns:  Date

Since: 06-27-2007

top

Date getDateThisMonth(int dayOfMonth)

Returns a new Date with the given day of this month.

Parameters:

  • int   dayOfMonth Required parameter.

Returns:  Date

Since: 06-27-2007

top

int getDay(Date date)

Returns the day of the month (1-31) of the given date.

Parameters:

  • Date   date Required parameter.

Returns:  int

Since: 06-27-2007

top

int getDayOrdinal(Date date)

Returns the Nth day of this date. If it is the 1st Thursday, this will return 1. If it is the 3rd Friday, this will return 3.

Parameters:

  • Date   date Required parameter.

Returns:  int

Since: 12-02-2021

top

Date getEndOfDay(Date date)

Returns a new Date which is the beginning of the given day (the time will be 11:59:59 PM).

Parameters:

  • Date   date Required parameter.

Returns:  Date

Since: 03-19-2009

top

Date getEndOfMonth(Date date)

Returns a new Date for the last day of the month of the given date.

Parameters:

  • Date   date Required parameter.

Returns:  Date

Since: 06-27-2007

top

Date getEndOfYear(Date date)

Returns a new Date for the last day of the year of the given date.

Parameters:

  • Date   date Required parameter.

Returns:  Date

Since: 06-27-2007

top

int getMonth(Date date)

Returns the month of the year (1-12) of the given date.

Parameters:

  • Date   date Required parameter.

Returns:  int

Since: 06-27-2007

top

Date getStartOfDay(Date date)

Returns a new Date which is the beginning of the given day (the time will be 12:00:00 AM).

Parameters:

  • Date   date Required parameter.

Returns:  Date

Since: 03-19-2009

top

Date getStartOfMonth(Date date)

Returns a new Date for the first day of the month of the given date.

Parameters:

  • Date   date Required parameter.

Returns:  Date

Since: 06-27-2007

top

Date getStartOfYear(Date date)

Returns a new Date for the first day of the year of the given date.

Parameters:

  • Date   date Required parameter.

Returns:  Date

Since: 06-27-2007

top

int getWeekOfMonth(Date date)

Returns the week of the month for the given date.

Parameters:

  • Date   date Required parameter.

Returns:  int

Since: 12-02-2021

top

int getWeekOfYear(Date date)

Returns the week of the year for the given date.

Parameters:

  • Date   date Required parameter.

Returns:  int

Since: 12-02-2021

top

int getYear(Date date)

Returns the year of the given date.

Parameters:

  • Date   date Required parameter.

Returns:  int

Since: 06-27-2007

top

boolean isDate(Date date1, Date date2)

Returns true if the two dates have the same day, month, and year

Parameters:

  • Date   date1 Required parameter.
  • Date   date2 Required parameter.

Returns:  boolean

Since: 08-05-2019

top

boolean isTime(Date date, int startHour, int startMinute, int endHour, int endMinute)

Returns true if the date is within the 24 hour start and end times.

Parameters:

  • Date   date Required parameter.
  • int   startHour  - min 0 max 23. Maximum allowed size of parameter: 23
  • int   startMinute  - min 0 max 59. Maximum allowed size of parameter: 59
  • int   endHour  - min 0 max 23. Maximum allowed size of parameter: 23
  • int   endMinute  - min 0 max 59. Maximum allowed size of parameter: 59

Returns:  boolean

Since: 09-30-2013

top

Date nextMonth(Date date)

Adds a month to the date and returns the date with the same day of week and week of month. Returns null if the operation is not possible.

Parameters:

  • Date   date Required parameter.

Returns:  Date

Since: 12-02-2021

top

Date parseComplexDate(String date)

Creates a date from the given string. Format can be almost any valid date (e.g. Mar. 3rd, 1956 or 5/5/2008). Returns null if the date cannot be parsed.

Parameters:

  • String   date Required parameter.

Returns:  Date

Since: 07-10-2008

top

Date parseDate(String date)

Creates a date from the given string. Format should be MM-dd-yyyy or MM/dd/yyyy

Parameters:

  • String   date Required parameter.

Returns:  Date

Since: 06-27-2007

top

Date parseDate(String date, String pattern)

Creates a date from the given string. Format should adhere to pattern. See java.text.SimpleDateFormat API documentation for more information about possible patterns.

Parameters:

  • String   date Required parameter.
  • String   pattern Required parameter.

Returns:  Date

Since: 09-14-2009

top

Date parseDatetime(String date)

Creates a date from the given string. String can be either integer value in milliseconds or in format MM-dd-yyyy or MM/dd/yyyy

Parameters:

  • String   date  - string to parse. Required parameter.

Returns:  Date

Since: 02-09-2012

top
Copyright © 2006 - 2024, ContractPal, Inc. All rights reserved. API Date: Nov 22, 2024 11:54 AM