DateTime CLASS

Represent a data time in Gregorian calendar.

Parent Class

All Members


TypeNameSignature
constructorDateTimepublic DateTime(int, int, int, int, int, int, int)
methoddiffpublic int diff(System.DateTime)
methodformatpublic String format(string)
methodgetDaypublic int getDay()
methodgetHourpublic int getHour()
methodgetMillipublic int getMilli()
methodgetMinutepublic int getMinute()
methodgetMonthpublic int getMonth()
method SgetNowpublic static DateTime getNow()
methodgetPartpublic int getPart(System.DateTimePart)
methodgetSecondpublic int getSecond()
methodgetYearpublic int getYear()
methodtoStringpublic String toString()

Constructors


public DateTime(int year, int month, int day, int hour, int minute, int second, int milli)

Create a datatime from each specified part.

Parameters

  • year year
  • month month, 1 - 12
  • day day, 1 - 31
  • hour hour, 0 - 23
  • minute minute, 0 - 59
  • second second, 0 - 59
  • milli millisecond, 0 - 999

Methods


public int diff(DateTime another)

Return the difference in milliseconds (this - another)

Parameters

  • another The other datetime to subtract from this one.

Returns

  • < 0 if the other datetime is later than this one; = 0 if equal; > 0 if earlier.

public String format(string fmt)

Convert the DateTime to a string with a format string, which may use the following characters as a placeholder for the corresponding data time part:

   y: (up to 4 digits) Year
   M: (up to 2 digits) Month in year (1 - 12)
   d: (up to 2 digits) Day in month (1 - 31)
   H: (up to 2 digits) Hour in day (0 - 23)
   m: (up to 2 digits) Minute in hour (0 - 59)
   s: (up to 2 digits) Second in minute (0 - 59)
   S: (up to 3 digits) Millisecond in second (000 - 999)

Other characters are rendered literally.

Parameters

  • fmt The format to use.

Returns

  • A date-time string formatted accordingly.


public int getDay()

Get day. Note this value is 1-based, within the range of [1, 31].

Returns


public int getHour()

Get hour.

Returns


public int getMilli()

Get millisecond.

Returns


public int getMinute()

Get minute.

Returns


public int getMonth()

Get month. Note this value is 1-based, within the range of [1, 12].

Returns


public static DateTime getNow()

Get the current local time.

Required Policies

  • System.Environment/read

Returns

  • The current local time.

public int getPart(DateTimePart part)

Get the value of a specified part from this datetime.

Parameters

  • part The part of this datetime to return.

Returns

  • The value of the required part.

public int getSecond()

Get second.

Returns


public int getYear()

Get year.

Returns


public String toString()

Convert the time to a default form (yyyy/MM/dd-hh:mm:ss.SSS).

Returns

  • A string in the format of yyyy/MM/dd-hh:mm:ss.SSS.