org.apache.tools.ant.util
public final class DateUtils extends Object
Since: Ant 1.5
Field Summary | |
---|---|
static DateFormat | DATE_HEADER_FORMAT
Format used for SMTP (and probably other) Date headers. |
static String | ISO8601_DATETIME_PATTERN
ISO8601-like pattern for date-time. |
static String | ISO8601_DATE_PATTERN
ISO8601-like pattern for date. |
static String | ISO8601_TIME_PATTERN
ISO8601-like pattern for time. |
Method Summary | |
---|---|
static String | format(long date, String pattern)
Format a date/time into a specific pattern. |
static String | format(Date date, String pattern)
Format a date/time into a specific pattern. |
static String | formatElapsedTime(long millis)
Format an elapsed time into a plurialization correct string.
|
static String | getDateForHeader()
Returns the current Date in a format suitable for a SMTP date
header.
|
static int | getPhaseOfMoon(Calendar cal)
Calculate the phase of the moon for a given date.
|
static Date | parseIso8601Date(String datestr)
Parse a string as a date using the ISO8601_DATE format which is
yyyy-MM-dd
|
static Date | parseIso8601DateTime(String datestr)
Parse a string as a datetime using the ISO8601_DATETIME format which is
yyyy-MM-dd'T'HH:mm:ss
|
static Date | parseIso8601DateTimeOrDate(String datestr)
Parse a string as a date using the either the ISO8601_DATETIME
or ISO8601_DATE formats.
|
Parameters: date the date to format expressed in milliseconds. pattern the pattern to use to format the date.
Returns: the formatted date.
Parameters: date the date to format expressed in milliseconds. pattern the pattern to use to format the date.
Returns: the formatted date.
Parameters: millis the elapsed time to report in milliseconds.
Returns: the formatted text in minutes/seconds.
Since: Ant 1.5.2
Code heavily influenced by hacklib.c in Nethack
The Algorithm:
moon period = 29.53058 days ~= 30, year = 365.2422 days days moon phase advances on first day of year compared to preceding year = 365.2422 - 12*29.53058 ~= 11 years in Metonic cycle (time until same phases fall on the same days of the month) = 18.6 ~= 19 moon phase on first day of year (epact) ~= (11*(year%19) + 18) % 30 (18 as initial condition for 1900) current phase in days = first day phase + days elapsed in year 6 moons ~= 177 days 177 ~= 8 reported phases * 22 + 11/22 for rounding
Returns: The phase of the moon as a number between 0 and 7 with 0 meaning new moon and 4 meaning full moon.
Since: 1.2, Ant 1.5
yyyy-MM-dd
Parameters: datestr string to be parsed
Returns: a java.util.Date object as parsed by the format.
Throws: ParseException if the supplied string cannot be parsed by this pattern.
Since: Ant 1.6
yyyy-MM-dd'T'HH:mm:ss
Parameters: datestr string to be parsed
Returns: a java.util.Date object as parsed by the format.
Throws: ParseException if the supplied string cannot be parsed by this pattern.
Since: Ant 1.6
Parameters: datestr string to be parsed
Returns: a java.util.Date object as parsed by the formats.
Throws: ParseException if the supplied string cannot be parsed by either of these patterns.
Since: Ant 1.6