Package org.daypilot.date
Class DateTime
java.lang.Object
org.daypilot.date.DateTime
A helper class for date/time calculations.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDateTime()
Creates a new DateTime representing current date and time (now).DateTime
(int year, int month, int day) DateTime
(long time) Creates a new DateTime object from a string in "2009-01-01T00:00:00" or "2009-01-01" format.Creates a new DateTime object from an existing java.sql.Timestamp object.Creates a new DateTime object from an existing java.util.Date object. -
Method Summary
Modifier and TypeMethodDescriptionaddDays
(int days) Returns a new DateTime object, increased by the specified number of days (accepts negative values).addHours
(int hours) addMilliSeconds
(int ms) addMinutes
(int minutes) Returns a new DateTime object, increased by the specified number of minutes (accepts negative values).addMonths
(int months) addSeconds
(int seconds) addYears
(int years) boolean
boolean
afterOrEqual
(DateTime another) boolean
boolean
beforeOrEqual
(DateTime another) protected Calendar
calendar()
static boolean
Return true if the string can be parsed using parse().int
boolean
static DateTime
fromDateLocal
(Date date) int
getDay()
int
int
int
int
int
getHour()
int
int
getMonth()
getMonthName
(DateTime date, Locale locale) long
getTicks()
static DateTime
getToday()
static DateTime
Returns beginning of this day in the given time zone.int
getYear()
inZoneByName
(TimeZone newZone) boolean
static DateTime
static DateTime
static DateTime
parseString
(String str) void
setTimezone
(TimeZone timezone) toDate()
toDateString
(Locale locale) toDateTimeString
(Locale locale) static DateTime
today()
toString()
Converts DateTime to a String in "2009-01-01T00:00:00" format.Formats the date using the specified pattern (see http://java.sun.com/javase/6/docs/api/index.html?java/text/SimpleDateFormat.html).Formats the date using the specified pattern (see http://java.sun.com/javase/6/docs/api/index.html?java/text/SimpleDateFormat.html) and locale.Converts DateTime to a String in ISO 8601 format ("2009-01-01T00:00:00").Converts DateTime to a sortable string format.Converts DateTime to a java.sql.Timestamp object.Returns a new DateTime instance with timezone set to tz.utc()
Returns a new DateTime instance with timezone set to UTC.
-
Field Details
-
UTC
-
ticks
protected long ticks -
EMPTY
-
MAX
-
MIN
-
-
Constructor Details
-
DateTime
public DateTime()Creates a new DateTime representing current date and time (now).- Parameters:
date
-
-
DateTime
public DateTime(long time) -
DateTime
Creates a new DateTime object from an existing java.sql.Timestamp object.- Parameters:
date
-
-
DateTime
-
DateTime
Creates a new DateTime object from an existing java.util.Date object.- Parameters:
date
-
-
DateTime
-
DateTime
Creates a new DateTime object from a string in "2009-01-01T00:00:00" or "2009-01-01" format.- Parameters:
date
-
-
DateTime
public DateTime(int year, int month, int day) -
DateTime
-
-
Method Details
-
calendar
-
fromDateLocal
-
toStringSortable
Converts DateTime to a sortable string format. Uses toStringIso8601().- Parameters:
date
-
-
toStringIso8601
Converts DateTime to a String in ISO 8601 format ("2009-01-01T00:00:00").- Parameters:
date
-
-
toString
Converts DateTime to a String in "2009-01-01T00:00:00" format. -
toString
Formats the date using the specified pattern (see http://java.sun.com/javase/6/docs/api/index.html?java/text/SimpleDateFormat.html). Uses the default locale (Locale.getDefault()).- Parameters:
pattern
-- Returns:
- Formatted String.
-
toDateString
-
toDateTimeString
-
toString
Formats the date using the specified pattern (see http://java.sun.com/javase/6/docs/api/index.html?java/text/SimpleDateFormat.html) and locale.- Parameters:
pattern
-locale
-- Returns:
- Formatted String.
-
toTimeStamp
Converts DateTime to a java.sql.Timestamp object.- Parameters:
date
-
-
addDays
Returns a new DateTime object, increased by the specified number of days (accepts negative values).- Parameters:
days
-- Returns:
-
addMinutes
Returns a new DateTime object, increased by the specified number of minutes (accepts negative values).- Parameters:
days
-- Returns:
-
parseAsLocal
-
parseString
-
parse
-
toDate
-
toDateLocal
-
getYear
public int getYear() -
getMonth
public int getMonth() -
getDay
public int getDay() -
getDatePart
-
add
-
getHour
public int getHour() -
getDayOfWeek
-
getDayOfWeekOrdinal
public int getDayOfWeekOrdinal()- Returns:
- Sunday = 0, Monday = 1, etc.
-
toDateString
-
getToday
-
today
-
getDayOfYear
public int getDayOfYear() -
getMinute
public int getMinute() -
getTimeOfDay
-
getTicks
public long getTicks() -
before
-
addHours
-
addMonths
-
minus
-
addYears
-
after
-
equals
-
addSeconds
-
beforeOrEqual
-
afterOrEqual
-
canParse
Return true if the string can be parsed using parse().- Parameters:
text
-- Returns:
-
isWeekend
public boolean isWeekend() -
getMonthName
-
firstDayOfMonth
-
getDaysOfMonth
public int getDaysOfMonth() -
getDaysOfYear
public int getDaysOfYear() -
firstDayOfYear
-
compareTo
-
smaller
-
bigger
-
tz
Returns a new DateTime instance with timezone set to tz. TimeZone affects formatting methods (e.g. toString()) and info methods (e.g. getDay()). It doesn't affect the actual time (milliseconds since 1970 UTC).- Parameters:
tz
-- Returns:
-
utc
Returns a new DateTime instance with timezone set to UTC. TimeZone affects formatting methods (e.g. toString()) and info methods (e.g. getDay()). It doesn't affect the actual time (milliseconds since 1970 UTC).- Returns:
-
getTimezone
-
setTimezone
-
addMilliSeconds
-
getToday
Returns beginning of this day in the given time zone. The timezone of the returned class is set to tz.- Parameters:
tz
-- Returns:
-
inZoneByName
-