JavaXT

Date Class

Used to parse, format, and compute dates

Constructors

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

Methods

add( int amount, String units ) returns java.util.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.)
clone( ) returns javaxt.utils.Date
Creates a copy of this object. Any modifications to the clone, will not affect the original.
compareTo( Object obj ) returns int
Compares two dates for ordering. Older dates appear first in an ordered list like a TreeSet.
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.)
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.
getCalendar( ) returns java.util.Calendar
Returns the java.utils.Calender representation of this object
getDate( ) returns java.util.Date
Returns the java.utils.Date representation of this object
getDay( ) returns int
Returns the current day of the month. Example: 11/14/2006 = 14
getDayInYear( ) returns int
Returns the day of the year. Example: 11/14/2006 = 318
getDayOfWeek( ) returns int
Returns the day of the week. Example: Monday = 1
getHour( ) returns int
Returns the current hour of the day. Example: 12:00 AM = 0, 1:00 PM = 13
getLocale( ) returns java.util.Locale
Used to retrieve the current local
getMilliSecond( ) returns int
Returns the current millisecond of the second. Example: 12:00:00:01 = 1
getMinute( ) returns int
Returns the current minute of the hour. Example: 12:01 = 1
getMonth( ) returns int
Returns the current month. Example: 11/14/2006 = 11
getMonthName( ) returns String
Returns the name of the month. Example: "January"
getSecond( ) returns int
Returns the current second of the minute. Example: 12:00:01 = 1
getTime( ) returns long
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
getTimeZone( ) returns java.util.TimeZone
Returns the current time zone. The time zone is used when comparing and formatting dates.
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 java.util.HashMap
Returns a hashmap of all known time zones. Includes time zones packaged with Java, Microsoft, and a few others.
getWeekdayName( ) returns String
Returns the name of the day of the week. Example: "Monday"
getWeekInMonth( ) returns int
Returns the week number in a given month. Example: 11/14/2006 = 3
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
hashCode( ) returns int
hasTimeStamp( ) returns boolean
Used to determine whether the date has a timestamp.
isAfter( String date ) returns boolean
isAfter( javaxt.utils.Date Date ) returns boolean
isBefore( String date ) returns boolean
isBefore( javaxt.utils.Date Date ) returns boolean
removeTimeStamp( ) returns void
Updates the date by removing the timestamp
setDate( java.util.Date date ) returns void
Used to update the current date using a predefined java.util.Date
setDate( String date, String format ) returns void
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.
setLocale( java.util.Locale locale ) returns void
Used to update the current local
setTimeZone( String timeZone ) returns void
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 void
Used to set the current time zone. The time zone is used when comparing and formatting dates.
setTimeZone( String timeZone, boolean preserveTimeStamp ) returns void
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 void
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.
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.
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.
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