# Class DateTime

java.lang.Object
org.daypilot.date.DateTime

public class DateTime extends Object
A helper class for date/time calculations.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final DateTime`
  `EMPTY`
  `static final DateTime`
  `MAX`
  `static final DateTime`
  `MIN`
  `protected long`
  `ticks`
  `static final TimeZone`
  `UTC`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DateTime()`
  Creates a new DateTime representing current date and time (now).
  `DateTime(int year, int month, int day)`
  `DateTime(long time)`
  `DateTime(long ticks, TimeZone tz)`
  `DateTime(String str)`
  Creates a new DateTime object from a string in "2009-01-01T00:00:00" or "2009-01-01" format.
  `DateTime(Timestamp timestamp)`
  Creates a new DateTime object from an existing java.sql.Timestamp object.
  `DateTime(Timestamp timestamp, boolean isLocal)`
  `DateTime(Date date)`
  `DateTime(Date date, boolean isLocal)`
  Creates a new DateTime object from an existing java.util.Date object.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `DateTime`
  `add(TimeSpan offset)`
  `DateTime`
  `addDays(int days)`
  Returns a new DateTime object, increased by the specified number of days (accepts negative values).
  `DateTime`
  `addHours(int hours)`
  `DateTime`
  `addMilliSeconds(int ms)`
  `DateTime`
  `addMinutes(int minutes)`
  Returns a new DateTime object, increased by the specified number of minutes (accepts negative values).
  `DateTime`
  `addMonths(int months)`
  `DateTime`
  `addSeconds(int seconds)`
  `DateTime`
  `addYears(int years)`
  `boolean`
  `after(DateTime another)`
  `boolean`
  `afterOrEqual(DateTime another)`
  `boolean`
  `before(DateTime another)`
  `boolean`
  `beforeOrEqual(DateTime another)`
  `DateTime`
  `bigger(DateTime another)`
  `protected Calendar`
  `calendar()`
  `static boolean`
  `canParse(String text)`
  Return true if the string can be parsed using parse().
  `int`
  `compareTo(DateTime another)`
  `boolean`
  `equals(Object another)`
  `DateTime`
  `firstDayOfMonth()`
  `DateTime`
  `firstDayOfYear()`
  `static DateTime`
  `fromDateLocal(Date date)`
  `DateTime`
  `getDatePart()`
  `int`
  `getDay()`
  `DayOfWeek`
  `getDayOfWeek()`
  `int`
  `getDayOfWeekOrdinal()`
  `int`
  `getDayOfYear()`
  `int`
  `getDaysOfMonth()`
  `int`
  `getDaysOfYear()`
  `int`
  `getHour()`
  `int`
  `getMinute()`
  `int`
  `getMonth()`
  `String`
  `getMonthName(DateTime date, Locale locale)`
  `long`
  `getTicks()`
  `TimeSpan`
  `getTimeOfDay()`
  `TimeZone`
  `getTimezone()`
  `static DateTime`
  `getToday()`
  `static DateTime`
  `getToday(TimeZone tz)`
  Returns beginning of this day in the given time zone.
  `int`
  `getYear()`
  `DateTime`
  `inZoneByName(TimeZone newZone)`
  `boolean`
  `isWeekend()`
  `TimeSpan`
  `minus(DateTime another)`
  `static DateTime`
  `parse(Object o, boolean isLocal)`
  `static DateTime`
  `parseAsLocal(Object o)`
  `static DateTime`
  `parseString(String str)`
  `void`
  `setTimezone(TimeZone timezone)`
  `DateTime`
  `smaller(DateTime another)`
  `Date`
  `toDate()`
  `Date`
  `toDateLocal()`
  `String`
  `toDateString()`
  `String`
  `toDateString(Locale locale)`
  `String`
  `toDateTimeString(Locale locale)`
  `static DateTime`
  `today()`
  `String`
  `toString()`
  Converts DateTime to a String in "2009-01-01T00:00:00" format.
  `String`
  `toString(String pattern)`
  Formats the date using the specified pattern (see http://java.sun.com/javase/6/docs/api/index.html?java/text/SimpleDateFormat.html).
  `String`
  `toString(String pattern, Locale locale)`
  Formats the date using the specified pattern (see http://java.sun.com/javase/6/docs/api/index.html?java/text/SimpleDateFormat.html) and locale.
  `String`
  `toStringIso8601()`
  Converts DateTime to a String in ISO 8601 format ("2009-01-01T00:00:00").
  `String`
  `toStringSortable()`
  Converts DateTime to a sortable string format.
  `Timestamp`
  `toTimeStamp()`
  Converts DateTime to a java.sql.Timestamp object.
  `DateTime`
  `tz(TimeZone tz)`
  Returns a new DateTime instance with timezone set to tz.
  `DateTime`
  `utc()`
  Returns a new DateTime instance with timezone set to UTC.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### UTC

    public static final TimeZone UTC

  - ### ticks

    protected long ticks

  - ### EMPTY

    public static final DateTime EMPTY

  - ### MAX

    public static final DateTime MAX

  - ### MIN

    public static final DateTime MIN

- ## Constructor Details

  - ### DateTime

    public DateTime()
    Creates a new DateTime representing current date and time (now).
    Parameters:
      `date` -

  - ### DateTime

    public DateTime(long time)

  - ### DateTime

    public DateTime(Timestamp timestamp)
    Creates a new DateTime object from an existing java.sql.Timestamp object.
    Parameters:
      `date` -

  - ### DateTime

    public DateTime(Timestamp timestamp, boolean isLocal)

  - ### DateTime

    public DateTime(Date date, boolean isLocal)
    Creates a new DateTime object from an existing java.util.Date object.
    Parameters:
      `date` -

  - ### DateTime

    public DateTime(Date date)

  - ### DateTime

    public DateTime(String str)
    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

    public DateTime(long ticks, TimeZone tz)

- ## Method Details

  - ### calendar

    protected Calendar calendar()

  - ### fromDateLocal

    public static DateTime fromDateLocal(Date date)

  - ### toStringSortable

    public String toStringSortable()
    Converts DateTime to a sortable string format. Uses toStringIso8601().
    Parameters:
      `date` -

  - ### toStringIso8601

    public String toStringIso8601()
    Converts DateTime to a String in ISO 8601 format ("2009-01-01T00:00:00").
    Parameters:
      `date` -

  - ### toString

    public String toString()
    Converts DateTime to a String in "2009-01-01T00:00:00" format.
    Overrides:
      `toString` in class `Object`
    Parameters:
      `date` -

  - ### toString

    public String toString(String pattern)
    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

    public String toDateString(Locale locale)

  - ### toDateTimeString

    public String toDateTimeString(Locale locale)

  - ### toString

    public String toString(String pattern, Locale locale)
    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

    public Timestamp toTimeStamp()
    Converts DateTime to a java.sql.Timestamp object.
    Parameters:
      `date` -

  - ### addDays

    public DateTime addDays(int days)
    Returns a new DateTime object, increased by the specified number of days (accepts negative values).
    Parameters:
      `days` -
    Returns:

  - ### addMinutes

    public DateTime addMinutes(int minutes)
    Returns a new DateTime object, increased by the specified number of minutes (accepts negative values).
    Parameters:
      `days` -
    Returns:

  - ### parseAsLocal

    public static DateTime parseAsLocal(Object o)

  - ### parseString

    public static DateTime parseString(String str)

  - ### parse

    public static DateTime parse(Object o, boolean isLocal)

  - ### toDate

    public Date toDate()

  - ### toDateLocal

    public Date toDateLocal()

  - ### getYear

    public int getYear()

  - ### getMonth

    public int getMonth()

  - ### getDay

    public int getDay()

  - ### getDatePart

    public DateTime getDatePart()

  - ### add

    public DateTime add(TimeSpan offset)

  - ### getHour

    public int getHour()

  - ### getDayOfWeek

    public DayOfWeek getDayOfWeek()

  - ### getDayOfWeekOrdinal

    public int getDayOfWeekOrdinal()
    Returns:
      Sunday = 0, Monday = 1, etc.

  - ### toDateString

    public String toDateString()

  - ### getToday

    public static DateTime getToday()

  - ### today

    public static DateTime today()

  - ### getDayOfYear

    public int getDayOfYear()

  - ### getMinute

    public int getMinute()

  - ### getTimeOfDay

    public TimeSpan getTimeOfDay()

  - ### getTicks

    public long getTicks()

  - ### before

    public boolean before(DateTime another)

  - ### addHours

    public DateTime addHours(int hours)

  - ### addMonths

    public DateTime addMonths(int months)

  - ### minus

    public TimeSpan minus(DateTime another)

  - ### addYears

    public DateTime addYears(int years)

  - ### after

    public boolean after(DateTime another)

  - ### equals

    public boolean equals(Object another)
    Overrides:
      `equals` in class `Object`

  - ### addSeconds

    public DateTime addSeconds(int seconds)

  - ### beforeOrEqual

    public boolean beforeOrEqual(DateTime another)

  - ### afterOrEqual

    public boolean afterOrEqual(DateTime another)

  - ### canParse

    public static boolean canParse(String text)
    Return true if the string can be parsed using parse().
    Parameters:
      `text` -
    Returns:

  - ### isWeekend

    public boolean isWeekend()

  - ### getMonthName

    public String getMonthName(DateTime date, Locale locale)

  - ### firstDayOfMonth

    public DateTime firstDayOfMonth()

  - ### getDaysOfMonth

    public int getDaysOfMonth()

  - ### getDaysOfYear

    public int getDaysOfYear()

  - ### firstDayOfYear

    public DateTime firstDayOfYear()

  - ### compareTo

    public int compareTo(DateTime another)

  - ### smaller

    public DateTime smaller(DateTime another)

  - ### bigger

    public DateTime bigger(DateTime another)

  - ### tz

    public DateTime tz(TimeZone 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

    public DateTime 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

    public TimeZone getTimezone()

  - ### setTimezone

    public void setTimezone(TimeZone timezone)

  - ### addMilliSeconds

    public DateTime addMilliSeconds(int ms)

  - ### getToday

    public static DateTime getToday(TimeZone tz)
    Returns beginning of this day in the given time zone. The timezone of the returned class is set to tz.
    Parameters:
      `tz` -
    Returns:

  - ### inZoneByName

    public DateTime inZoneByName(TimeZone newZone)