std/time/format▲toc

Formatting of time into a string.

.

fun format( t : timestd/time/time/time: V, fmt : stringstd/core/types/string: V, locale : ? time-localestd/time/locale/time-locale: V ) : stringstd/core/types/string: V

Format a time according to format string fmt and using a optional time locale (= time-locale-en-isostd/time/locale/time-locale-en-iso: time-locale).

Letters (a to z) are always interpreted as a pattern where unknown letter patterns are ignored. Any literal text should be quote-escaped i.e. use "'GMT'ZZ" to display as "GMT-07:00" (in the PST time zone). Any characters other then an ascii letter are displayed as is.

Patterns of 2 letters are zero-padded on the left to always display as 2 digits. Allowed patterns:

There are also various forms to display dates and times in a locale specific way. We give examples in English and Dutch. The lower-case l variants use short names for month- and day names.

After formatting, any left- or right white space is trimmed. This allows specifiers like "YYYY E C" that display correctly even if the era or calendar name is empty.

For example, to display a time in the standard Internet Message Format you can use now().formatstd/time/format/format: (t : time, fmt : string, locale : ? time-locale) -> string("ddd, D MMM Y HH:mm:ss zz") displayed as "Tue, 27 Sep 2016 06:36:55 -0700" for example.
A standard ISO string can be formatted as, "YYYY-MM-DD'T'HH:mm:ssFFFFFFFFFZ C".

fun show-imf( t : timestd/time/time/time: V ) : stringstd/core/types/string: V

Show time as a standard Internet Message Format date.
For example now().show-imfstd/time/format/show-imf: (t : time) -> string returns "Fri, 9 Oct 2016 11:57:45 -0700".

fun show-in-locale( t : timestd/time/time/time: V, locale : ? time-localestd/time/locale/time-locale: V ) : stringstd/core/types/string: V

Show the time as a human readable string in the given locale (=time-locale-enstd/time/locale/time-locale-en: time-locale) For example now().show-en -> "Thu, 8 Oct 2016, 12:20pm". Uses the "llll" format string.

fun show-in-locale-date( t : timestd/time/time/time: V, locale : ? time-localestd/time/locale/time-locale: V ) : stringstd/core/types/string: V

Show the date in human readable string in the given locale (=time-locale-enstd/time/locale/time-locale-en: time-locale). For example now().show-en-date -> "Thu, 8 Oct 2016". Uses the "ll" format string.

fun show-iso( t : timestd/time/time/time: V ) : stringstd/core/types/string: V

Show a time as a standard ISO string. Will use automatic week date or month date format for the cal-iso-week and cal-iso-month calendars.

fun show-iso-date( t : timestd/time/time/time: V ) : stringstd/core/types/string: V

Show a time as a standard ISO date. Will use automatic week date or month date format for the cal-iso-week and cal-iso-month calendars.

private import std/core/typesstd/core/types, std/core/hndstd/core/hnd, std/core/exnstd/core/exn, std/core/boolstd/core/bool, std/core/orderstd/core/order, std/core/charstd/core/char, std/core/intstd/core/int, std/core/vectorstd/core/vector, std/core/stringstd/core/string, std/core/sslicestd/core/sslice, std/core/liststd/core/list, std/core/maybestd/core/maybe, std/core/eitherstd/core/either, std/core/tuplestd/core/tuple, std/core/showstd/core/show, std/core/debugstd/core/debug, std/core/delayedstd/core/delayed, std/core/consolestd/core/console, std/corestd/core, std/core/undivstd/core/undiv, std/text/parsestd/text/parse, std/num/ddoublestd/num/ddouble, std/time/timestampstd/time/timestamp, std/time/durationstd/time/duration, std/time/instantstd/time/instant, std/time/datestd/time/date, std/time/calendarstd/time/calendar, std/time/timestd/time/time, std/time/localestd/time/locale