DateTime implementation based on amount of seconds since unix epoch. * By default all date/time data returned is in UTC.

Constructor

inline new (time:Float)

Constructor

Parameters:

time
  • unix timestamp (amount of seconds since 1970-01-01 00:00:00)

Methods

add (period:DTPeriod):DateTime

Add time period to this timestamp. Returns new DateTime.

inline daysInThisMonth ():Int

Return amount of days in current month

format (format:String):String

Format this timestamp according to format

Day

  • %d Two-digit day of the month (with leading zeros) 01 to 31
  • %e Day of the month, with a space preceding single digits. 1 to 31
  • %j Day of the year, 3 digits with leading zeros 001 to 366
  • %u ISO-8601 numeric representation of the day of the week 1 (for Monday) though 7 (for Sunday)
  • %w Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)

Month

  • %m Two digit representation of the month 01 (for January) through 12 (for December)

Year

  • %C Two digit representation of the century (year divided by 100, truncated to an integer) 19 for the 20th Century
  • %y Two digit representation of the year Example: 09 for 2009, 79 for 1979
  • %Y Four digit representation for the year Example: 2038

Week

  • %V ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays,
  • with Monday being the start of the week 01 through 53

Time

  • %H Two digit representation of the hour in 24-hour format 00 through 23
  • %k Two digit representation of the hour in 24-hour format, with a space preceding single digits 0 through 23
  • %I Two digit representation of the hour in 12-hour format 01 through 12
  • %l (lower-case 'L') Hour in 12-hour format, with a space preceding single digits 1 through 12
  • %M Two digit representation of the minute 00 through 59
  • %p upper-case 'AM' or 'PM' based on the given time Example: AM for 00:31, PM for 22:23
  • %P lower-case 'am' or 'pm' based on the given time Example: am for 00:31, pm for 22:23
  • %r Same as "%I:%M:%S %p" Example: 09:34:17 PM for 21:34:17
  • %R Same as "%H:%M" Example: 00:35 for 12:35 AM, 16:44 for 4:44 PM
  • %S Two digit representation of the second 00 through 59
  • %T Same as "%H:%M:%S" Example: 21:34:17 for 09:34:17 PM

Time and Date Stamps

  • %D Same as "%m/%d/%y" Example: 02/05/09 for February 5, 2009
  • %F Same as "%Y-%m-%d" (commonly used in database datestamps) Example: 2009-02-05 for February 5, 2009
  • %s Unix Epoch Time timestamp Example: 305815200 for September 10, 1979 08:40:00 AM

Miscellaneous

  • %% A literal percentage character ("%")

inline getDate ():Date

Create standart Date class instance using unix timestamp of this one

inline getDay ():Int

Get day number (1-31)

inline getHour ():Int

Get hour number (0-23)

getHour12 ():Int

Get hour number in 12-hour-clock

inline getMinute ():Int

Get minumte number (0-59)

inline getMonth ():Int

Get month number (1-12)

inline getMonthStart (month:DTMonth):DateTime

Get date/time of the first second of specified month.

inline getSecond ():Int

Get second number (0-59)

inline getTime ():Float

Get unix timestamp (amount of seconds)

getWeek ():Int

Get current week number within a year according to the ISO 8601 date and time standard

getWeekDay (?mondayBased:Bool):Int

Get day of the week.

Returns 0-6 (Sunday-Saturday) by default.

Returns 1-7 (Monday-Sunday) if mondayBased = true

inline getWeekDayNum (weekDay:DTWeekDay, ?num:Int):DateTime

Get DateTime of a specified weekDay in this month, which is the numst in current month.

*
*   E.g. get DateTime of the second Sunday in current month.
*   If `num` is negative, then required `weekDay` will be searched from the end of this month.
*   If `num` == 0, returns a copy of this DateTime instance

getYear ():Int

Get year number (4 digits)

inline getYearDay ():Int

Get day number within a year (1-366)

isLeapYear ():Bool

Check if this is leap year

snap (period:DTSnap):DateTime

Snap to nearest year, month, day, hour, minute, second or week. Returns new DateTime.

toString ():String

Convert to string representation in format YYYY-MM-DD HH:MM:SS

utc ():DateTime

Assuming this instance is your local time, convert it ot UTC using current time offset of your timezone.

Does not use your timezone data, just current time offset.

If you dont care about your timezone and just need to convert your local time to utc, use this method instead of Timezone class.

Returns new DateTime instance

weeksInThisYear ():Int

Get amount of weeks in this year (52 or 53)

Static variables

staticinline read onlySECONDS_IN_DAY:Int

staticinline read onlySECONDS_IN_HOUR:Int

staticinline read onlySECONDS_IN_LEAP_YEAR:Int

staticinline read onlySECONDS_IN_MINUTE:Int

staticinline read onlySECONDS_IN_WEEK:Int

staticinline read onlySECONDS_IN_YEAR:Int

Static methods

staticinline daysInMonth (month:Int, ?isLeapYear:Bool):Int

Get amount of days in specified month (1-12). If month is 2 (February), you need to specify whether you want to get amount of days in leap year or not.

staticinline fromDate (date:Date):DateTime

Make DateTime instance using unix timestamp retreived from date

Returns UTC time.

staticinline fromString (str:String):DateTime

Convert 'YYYY-MM-DD hh:mm:ss' or 'YYYY-MM-DD' or 'YYYY-MM-DDThh:mm:ss[.SSS]Z' to DateTime

Assumes provided string represents UTC time.

Returns UTC time.

Throws:

String
  • if provided string is not in correct format

staticinline fromTime (time:Float):DateTime

Make DateTime from unix timestamp (amount of seconds)

Returns UTC time.

staticinline isLeap (year:Int):Bool

Check if specified year is a leap year

staticlocal ():DateTime

Get current local date&time.

Returns user's local date/time.

staticinline make (?year:Int, ?month:Int, ?day:Int, ?hour:Int, ?minute:Int, ?second:Int):DateTime

Build DateTime using specified components

Builds UTC time.

Parameters:

year
month
  • 1-12
day
  • 1-31
hour
  • 0-23
minute
  • 0-59
second
  • 0-59

staticinline now ():DateTime

Get current UTC date&time

staticweeksInYear (year:Int):Int

Get amount of weeks in year (52 or 53)