Date Class

Used to parse, format, and compute dates

Constructors

Date( )
Date( java.util.Date date )
Date( Calendar calendar )
Date( long milliseconds )
Date( String date )
Date( String date, String format )

Properties

INTERVAL_MILLISECONDS
INTERVAL_SECONDS
INTERVAL_MINUTES
INTERVAL_HOURS
INTERVAL_DAYS
INTERVAL_WEEKS
INTERVAL_MONTHS
INTERVAL_YEARS

Public Methods

setDate( String date, String format ) returns javaxt.utils.Date
Used to update the current date using a date string. The format parameter is used to create a SimpleDateFormat to parse the input date string.
setDate( java.util.Date date ) returns javaxt.utils.Date
Used to update the current date using a predefined java.util.Date
setLocale( Locale locale ) returns javaxt.utils.Date
Used to update the current local
getLocale( ) returns Locale
Returns the current local
setTimeZone( String timeZone, boolean preserveTimeStamp ) returns javaxt.utils.Date
Used to set the current time zone. The time zone is used when comparing and formatting dates.
timeZoneName of the time zone (e.g. "UTC", "EDT", etc.)
preserveTimeStampFlag used to indicate whether to preserve the timestamp when changing time zones. Normally, when updating the timezone, the timestamp is updated to the new timezone. For example, if the current time is 4PM EST and you wish to switch to UTC, the timestamp would be updated to 8PM. The preserveTimeStamp flag allows users to preserve the the timestamp so that the timestamp remains fixed at 4PM.
setTimeZone( java.util.TimeZone timeZone, boolean preserveTimeStamp ) returns javaxt.utils.Date
Used to set the current time zone. The time zone is used when comparing and formatting dates.
timeZoneTime zone (e.g. "UTC", "EDT", etc.)
preserveTimeStampFlag used to indicate whether to preserve the timestamp when changing time zones. Normally, when updating the timezone, the timestamp is updated to the new timezone. For example, if the current time is 4PM EST and you wish to switch to UTC, the timestamp would be updated to 8PM. The preserveTimeStamp flag allows users to preserve the the timestamp so that the timestamp remains fixed at 4PM.
setTimeZone( String timeZone ) returns javaxt.utils.Date
Used to set the current time zone. The time zone is used when comparing and formatting dates.
timeZoneName of the time zone (e.g. "UTC", "EST", etc.)
setTimeZone( java.util.TimeZone timeZone ) returns javaxt.utils.Date
Used to set the current time zone. The time zone is used when comparing and formatting dates.
getTimeZone( ) returns java.util.TimeZone
Returns the current time zone. The time zone is used when comparing and formatting dates.
hashCode( ) returns int
toString( ) returns String
Returns the current date as a String in the following format: "EEE MMM dd HH:mm:ss z yyyy"
toString( String format ) returns String
Used to format the current date into a string.
formatPattern used to format the date (e.g. "MM/dd/yyyy hh:mm a", "EEE MMM dd HH:mm:ss z yyyy", etc). Please refer to the java.text.SimpleDateFormat class for more information.
toString( String format, String timeZone ) returns String
toString( String format, java.util.TimeZone timeZone ) returns String
toISOString( ) returns String
Returns the date in ISO 8601 format (e.g. "2013-01-04T05:00:00.000Z"). Note that ISO dates are in UTC.
toLong( ) returns long
Returns a long integer used to represent the Date in the following format: "yyyyMMddHHmmssSSS". The time zone is automatically set to UTC. This is useful for perform simple date comparisons and storing dates in a database as integers (e.g. SQLite). Here's an example of how to go from a date to a long and a long to a date:
        javaxt.utils.Date orgDate = new javaxt.utils.Date();
        Long l = orgDate.toLong(); //"yyyyMMddHHmmssSSS" formatted long in UTC
        javaxt.utils.Date newDate = new javaxt.utils.Date(l+"");
        newDate.setTimeZone("UTC", true);
        System.out.println(newDate);
    
Note that this method is different from the getTime() method which returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.
clone( ) returns Date
Creates a copy of this object. Any modifications to the clone, will not affect the original.
equals( Object obj ) returns boolean
Used to compare dates and determine whether they are equal.
objAccepts a java.util.Date, a javaxt.utils.Date, or a String.
compareTo( javaxt.utils.Date date, String units ) returns long
Used to compare dates. Returns the number of intervals between two dates. If the given date is in the future, returns a negative value. If the given date is in the past, returns a positive value.
date
unitsUnits of measure (e.g. hours, minutes, seconds, weeks, months, years, etc.)
compareTo( java.util.Date date, String units ) returns long
Used to compare dates. Returns the number of intervals between two dates
date
unitsUnits of measure (e.g. hours, minutes, seconds, weeks, months, years, etc.)
isBefore( String date ) returns boolean
isBefore( javaxt.utils.Date Date ) returns boolean
isAfter( String date ) returns boolean
isAfter( javaxt.utils.Date Date ) returns boolean
add( int amount, String units ) returns javaxt.utils.Date
Used to update the current date by adding to (or subtracting from) the current date. Example:
    javaxt.utils.Date date = new javaxt.utils.Date();
    System.out.println("Today is: " + date);
    date.add(-1, "day");
    System.out.println("Yesterday was: " + date);
    
amount
unitsUnit of measure (e.g. hours, minutes, seconds, days, weeks, months, years, etc.)
setDate( int year, int month, int day ) returns javaxt.utils.Date
Used to update the year, month and day of the current date.
year
monthValid range is 1-12
dayValid range is 1-31
setTime( int hours, int minutes, int seconds, int milliseconds ) returns javaxt.utils.Date
Used to update the hours, minutes, seconds, and milliseconds of the current date.
getDate( ) returns java.util.Date
Returns the java.utils.Date representation of this object
getTime( ) returns long
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
getCalendar( ) returns Calendar
Returns the java.utils.Calender representation of this object
getWeekdayName( ) returns String
Returns the name of the day of the week. Example: "Monday"
getMonthName( ) returns String
Returns the name of the month. Example: "January"
getDayOfWeek( ) returns int
Returns the day of the week (1-7) where Monday = 1
getWeekInMonth( ) returns int
Returns the week number in a given month. Example: 11/14/2006 = 3
getDayInYear( ) returns int
Returns the day of the year. Example: 11/14/2006 = 318
getWeekInYear( ) returns int
Returns the week number within a given year. Example: 11/14/2006 = 46
getYear( ) returns int
Returns the current year. Example: 11/14/2006 = 2006
getMonth( ) returns int
Returns the current month. Example: 11/14/2006 = 11
getDay( ) returns int
Returns the current day of the month. Example: 11/14/2006 = 14
getHour( ) returns int
Returns the current hour of the day. Example: 12:00 AM = 0, 1:00 PM = 13
getMinute( ) returns int
Returns the current minute of the hour. Example: 12:01 = 1
getSecond( ) returns int
Returns the current second of the minute. Example: 12:00:01 = 1
getMilliSecond( ) returns int
Returns the current millisecond of the second. Example: 12:00:00:01 = 1
hasTimeStamp( ) returns boolean
Used to determine whether the date has a timestamp.
removeTimeStamp( ) returns javaxt.utils.Date
Updates the date by removing the timestamp
compareTo( Object obj ) returns int
Compares two dates for ordering. Older dates appear first in an ordered list like a TreeSet.

Static Methods

sortDates( java.util.List dates ) returns java.util.List
Static method used to sort dates in a list. Older dates appear first in the output.
getTimeZone( String timezone ) returns java.util.TimeZone
Static method used to return a timezone for a given ID. Unlike the java.util.TimeZone.getTimeZone() method, this method will return a null if a given ID cannot be understood.
timezoneThe name or ID of a TimeZone. Supports common abbreviations such as "EST" or "EDT", full names such as "Eastern Standard Time" or "America/New York", and raw GMT offsets such as "GMT-8:00".
getTimeZones( ) returns HashMap<String, String>
Returns a hashmap of all known time zones. Includes time zones packaged with Java, Microsoft, and a few others.