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.
toString( String format, String timeZone ) returns String Used to format the current date into a string in a given timezone.
toString( String format, java.util.TimeZone timeZone ) returns String Used to format the current date into a string. format( String format ) returns String Used to format the current date into a string. Same as toString(format). 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
isBefore( String date ) returns boolean Returns true if a given date is before the current date isBefore( javaxt.utils.Date Date ) returns boolean Returns true if a given date is before the current date isAfter( String date ) returns boolean Returns true if a given date is after the current date isAfter( javaxt.utils.Date Date ) returns boolean Returns true if a given date is after the current date 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);
subtract( int amount, String units ) returns javaxt.utils.Date Used to update the current date by subtracting from the current 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 the current date. 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 the current date. getLocalDate( ) returns LocalDate Returns a java.time.LocalDate representation of the current date. 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 hasTimeStamp( ) returns boolean Returns true if the date has an hour, minute, second, or millisecond greater than zero. compareTo( Object obj ) returns int Compares two dates for ordering. Older dates appear first in an ordered list like a TreeSet. Static MethodsgetMonthsBetween( javaxt.utils.Date start, javaxt.utils.Date end ) returns double Returns fractional month difference between two dates. This method will return whole numbers (1, 2, 3, etc) if the two dates fall on the same day of the month (e.g. "2023-03-01" v "2023-04-01" or "2023-03-14" v "2023-04-14"). Returns a decimal value less than or equal to 1 (<=1) if the dates fall within the same month (e.g. "2024-01-01" v "2024-01-31" yields 1.0 and "2024-01-01" v "2024-01-30" yields 0.968). Otherwise, returns the number of full months between the two dates plus a fractional value (e.g. "2023-01-27" v "2023-02-28" yields 1.0357). The decimal value (numbers after the decimal point) represent fractions of a month. Roughly speaking, a day is 0.03 of a month. There are some interesting results when comparing dates around the end of two different months. Specifically when comparing a longer month to shorter month. For example:
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.
getTimeZones( ) returns HashMap<String, String> Returns a hashmap of all known time zones. Includes time zones packaged with Java, Microsoft, and a few others. |