JavaXT
|
|||||||||||||||||||||||||||||||||||
Date ClassUsed to parse, format, and compute dates
Constructors Date( )
PropertiesINTERVAL_MILLISECONDS
INTERVAL_SECONDS
INTERVAL_MINUTES
INTERVAL_HOURS
INTERVAL_DAYS
INTERVAL_WEEKS
INTERVAL_MONTHS
INTERVAL_YEARS
Public MethodssetDate( 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 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.
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.
setTimeZone( String timeZone ) returns javaxt.utils.Date Used to set the current time zone. The time zone is used when comparing and formatting dates.
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. 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.
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.
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.
compareTo( java.util.Date date, String units ) returns long Used to compare dates. Returns the number of intervals between two dates
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);
setDate( int year, int month, int day ) returns javaxt.utils.Date Used to update the year, month and day of the current date.
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" 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 getHour( ) returns int Returns the current hour of the day. Example: 12:00 AM = 0, 1:00 PM = 13 getMilliSecond( ) returns int Returns the current millisecond of the second. Example: 12:00:00:01 = 1 compareTo( Object obj ) returns int Compares two dates for ordering. Older dates appear first in an ordered list like a TreeSet. Static MethodssortDates( 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.
getTimeZones( ) returns HashMap<String, String> Returns a hashmap of all known time zones. Includes time zones packaged with Java, Microsoft, and a few others. |