DtpDate()

Parse the date according to the format specified.

Syntax

public DtpDate()
  
 public DtpDate(String dateTimeStr, String format)
  
 public DtpDate(String dateTimeStr, String format, String[] monthNames,
    String[] shortMonthNames)
  
 public DtpDate(long msSince1970, boolean isLocalTime)
 

Parameters

dateTimeStr
The date-time in the form of a string.

format
The date format. See Notes for details.

monthNames
An array of strings representing the full 12 month names. If null, the default value is January, February, March, and so on.

shortMonthNames
An array of strings representing the short month name. If this is null but monthNames is not null, this value is the first 3 letters of the full month names, such as Jan, Feb, Mar, Apr, and so on.

msSince1970
The number of milliseconds since January 1, 1970 00:00:00.

isLocalTime
Set this to true if the time is already a local time, or to false otherwise.

Return values

None

Exceptions

DtpDateException - When the constructor encounters parsing errors. This may occur if the date is not in the specified format.

Notes

The first form of the constructor does not take any parameters. It assigns the current date on the system to the new DtpDate object. It does not throw DtpDateException.

The second and the third forms of the constructor parse the date according to the specified date format and extract out the day, month, year, hour, minute, and second values. These can be retrieved and reformatted later with other DtpDate methods.

For example, a month can be retrieved in one of the following formats:

The retrieved data does not depend of the context of the other data.

You can change the full-name and short-name representations of the month in the following ways:

The fourth form of the constructor takes the number of milliseconds since January 1, 1970 00:00:00. Many applications represent the date in this manner.

Date format

In the date format, the date always precedes the time. The time is optional. If it is missing in a date-time string, the hours, minutes, and seconds have a default value of 00.

The date format uses the following case sensitive key letters:
D day
M month
Y year
h hours
m minutes
s seconds

These key letters may be separated by a separator such as "/" or "-".

Examples

The following examples show the DtpDate() constructor creating new date objects aDate, date2, and date3:

Dtpdate aDate = new DtpDate("5/21/1997 15:23:01", "M/D/Y h:m:s");
 DtpDate date2 = new DtpDate("05211997 152301", "MDY hms"); 
 DtpDate date3 = new DtpDate("Jan 10, 1999 10:00:00", "M D, Y h:m:s");
 

The following date format results in the DtpDateException being thrown:

h:m:s D/M/Y
 

Copyright IBM Corp. 1997, 2003