format method

String format(
  1. String pattern, {
  2. bool persianDigits = false,
  3. JalaliEra era = JalaliEra.solarHijri,
})

Formats this date with pattern.

Token Output
yyyy year, at least four digits
yy last two digits of the year
yw year in Persian words
MMMM Persian month name
MM month, two digits
M month
dd day, two digits
d day
dw ordinal day in Persian words, یکم
EEEE Persian weekday name
E one-letter Persian weekday name
D day of the year
Q quarter, 1 to 4
HH hour (0 to 23), two digits
H hour (0 to 23)
hh hour (1 to 12), two digits
h hour (1 to 12)
mm minute, two digits
m minute
ss second, two digits
s second
a ق.ظ before noon, ب.ظ from noon
B dayPeriod, for example صبح or عصر
BBBB dayPeriod, with بعدازظهر for ظهر

The longest token wins, and every other character is copied as is. Text in single quotes is copied without looking for tokens, and two single quotes write one: format("'ساعت' HH:mm") gives ساعت 14:30, and format("d 'o''clock'") gives 1 o'clock. An unclosed quote runs to the end of the pattern.

Throws StateError for a time token when hasTime is false.

With persianDigits, numbers produced by tokens are written as ۰ to ۹; literal text in pattern is copied unchanged.

yyyy, yy, and yw number the year in era, Solar Hijri by default: format('yyyy', era: JalaliEra.shahanshahi) gives 2585 for 1405. format('EEEE dw MMMM yw') writes the whole date in words, see toPersianWords.

Implementation

String format(
  String pattern, {
  bool persianDigits = false,
  JalaliEra era = JalaliEra.solarHijri,
}) =>
    formatPattern(
      pattern,
      _tokens,
      (token) => _formatToken(token, year + era.offset),
      persianDigits: persianDigits,
    );