Lasso permits working with dates and times by using [Date] objects. A [Date] object holds a date/time value down to millisecond precision. This date/time value includes a timezone and the daylight saving time offset is computed using that timezone.
[Date] objects permit date arithmetic, adding and subtracting dates, as well as manipulating the individual year, month, day, hour, minute, second and millisecond fields.
[Date] objects are able to format themselves into strings, using a variety of options and formatting flags. Each [Date] is associated with a [Locale]. This [Locale] controls the default formatting applied to a date when it is converted into a string, taking localization into account. See the table of formatting flags on [Date->Format] or see ICU: Formatting Dates and Times for greater details.
A date object can be created by using one of the following methods:
date()
Create a new date object set to the current date and time, using the current default locale and timezone.
date(-year=void, -month=void, -day=void,
-hour=void, -minute=void, -second=void,
-dateGMT=void, -locale::locale=locale_default)
Create a new date object, optionally indicating specific values for the individual fields. The date is based off the current date, with any the modifications applied to that.
date(dateStr::string, -format::string=void, -locale::locale=locale_default)
Create a date object by parsing the provided string. Many standard date patterns are automatically detected, but a custom or specific date pattern can be indicated using the -format keyword parameter. See the table below for the list of automatically detected date string formats.
date(date::integer, -locale::locale=locale_default)
Create a date object with an integer value representing the number of seconds since midnight, January 1, 1970.
date(date::decimal, -locale::locale=locale_default)
Create a date object with an decimal value representing the number of seconds since midnight, January 1, 1970.
The automatically recognized date formats are shown below.
Format String | Notes |
---|---|
yyyy-MM-dd'T'HH:mm:ss | |
yyyy-MM-dd'T'HH:mm | |
yyyy-MM'T'HH:mm:ss | |
yyyy-MM'T'HH:mm | |
yyyy-MM-dd HH:mm:ss | |
yyyy-MM-dd HH:mm | |
yyyy-MM HH:mm:ss | |
yyyy-MM HH:mm | |
MM/dd/yyyy HH:mm:ss | |
MM/dd/yyyy HH:mm | |
MM/yyyy HH:mm:ss | |
MM/yyyy HH:mm | |
MM/dd/yyyy hh:mm:ss a | |
MM/dd/yyyy hh:mm a | |
MM/yyyy hh:mm:ss a | |
MM/yyyy hh:mm a | |
yyyy-MM-dd | |
yyyy-MM | |
MM/dd/yyyy | |
yyyy/mm | |
yyyyMMdd'T'HH:mm:ss | |
yyyyMMdd'T'HH:mm | |
yyyyMM'T'HH:mm:ss | |
yyyyMM'T'HH:mm | |
hh:mm:ss a | |
hh:mm a | |
HH:mm:ss | |
HH:mm | |
EEE, d MMM yyyy HH:mm:ss Z | rfc2822 |
d MMM yyyy HH:mm:ss Z | rfc2822 with omitted optional dayname |
EEE MMM d HH:mm:ss z yyyy | |
yyyyMMddHHmmss | mysql timestamp |
yyyyMMdd'T'HHmmss | |
yyyyMMdd'T'HHmm | |
yyyyMMdd'T'HH | |
yyyyMMdd | |
yyyyMM | |
yyyy |
date
date('Date String')
date('Date String', -format='Format String')
date(Integer Seconds Since 1970-01-01 00:00:00 GMT)
date(Decimal Seconds Since 1970-01-01 00:00:00 GMT)
Use the [Date] method with an appropriate -format parameter. The following example uses a typical Canadian date string, converts the string to a Lasso date object, and returns the value re-formatted as a typical Lasso date.
Code
date('20/04/2011 16:20:24', -format='dd/MM/yyyy HH:mm:ss')->format('yyyy-MM-dd HH:mm:ss')
Result
2011-04-20 16:20:24
Create a [Date] object set to the current time and timezone. Reset the timezone to be GMT.
Code
local(now = date)
#now->format("HH:mm:ss zzz '('Z')'") // show current time
#now->timezone = 'GMT'
#now->format("HH:mm:ss zzz '('Z')'") // show current time as GMT
Result
14:09:49 EDT (-0400) 18:09:49 GMT+00:00 (+0000)
Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft
Recent Comments