Fog Creek Software
Fog Creek Software

CityDesk 2.0-Documentation
Controlling the Formatting of Dates and Times

Dates and times are displayed differently in different languages and regions of the world. For example, in the United States, it is common to put the month before the date; in the rest of the world the date goes before the month. So 1/3/03 means January 3 in the US but in the United Kingdom it would mean March 1st.

When CityDesk displays a date or time, it tries to figure out which language to use by looking at the site's language; this is specified in the languages dialog. If you have a multilingual site, for example, English and French, each version of the site will have dates and times formatted in the appropriate language.

If CityDesk doesn't recognize the language the site is in, it will format dates and times in English. A complete list of languages that CityDesk recognizes is here.

If you would like to use a different format, insert the following CityScript in a template or file before you display dates or times:

{$ setDateTimeFormat "language" "dateFormat" "timeFormat" $}

You can change the format as often as you need to. For example, to display the date in both English and Spanish:

{$setDateTimeFormat "English" "dddd, MMMM dd, yyyy" "hh:mm"$}
{$.filedDate$}

({$setDateTimeFormat "Spanish" "^dddd, MMMM dd, yyyy" "hh:mm"$}
{$.filedDate$})

language can be any of the language names listed here. If language is CityDesk will use the site's language. For example, to force CityDesk to use the appropriate short date format for each language in a multilingual site, type:

{$setDateTimeFormat "*" "short" "hh:mm"$}

As another example, to force CityDesk to use the long date format in Nynorsk Norwegian:

{$setDateTimeFormat "Norwegian (Nynorsk)" "long" "hh:mm"$}

dateFormat can be long or short or a string describing a custom format. long will use the preferred full date format for the given language; short will use an abbreviated format such as 01/01/03. To control the date format more precisely, you can provide a string made up of any combination of the following codes:

Code: Is Replaced With:
d Day of month, without leading zero for single-digit days
dd Day of month, with leading zero for single-digit days
ddd Day of the week, as a three-letter abbreviation
dddd Day of the week, using the full name
M Month, as digits, with no leading zero for single-digit months
MM Month, as digits, with leading zero for single-digit months
MMM Month, as a three-letter abbreviation
MMMM Month, using the full name
y Year, as two digits, but with no leading zero for years less than 10
yy Year, as two digits, with leading zero for years less than 10
yyyy Year represented by four full digits
gg Period or era string (for certain languages)

timeFormat is a string consisting of a combination of the following codes:

Code: Is Replaced With:
h Hours with no leading zero for single-digit hours, using 12-hour clock
hh Hours with leading zero for single-digit hours, using 12-hour clock
H Hours with no leading zero for single-digit hours, using 24-hour clock
HH Hours with leading zero for single-digit hours, using 24-hour clock
m Minutes with no leading zero  for single-digit minutes
mm Minutes with leading zero  for single-digit minutes
s Seconds with no leading zero for single-digit seconds
ss Seconds with leading zero for single-digit seconds
t One character am/pm indicator ("a" or "p")
tt Multicharacter am/pm indicator

To include letters in the date or time format string without their being replaced by values, enclose them in single quotes. For example:

{$ setDateTimeFormat "Spanish" "d 'de' MMMM, yyyy" "HH':'mm" $}

Because the de is in single quotes, the d will not be replaced by the day of the month.

To produce a single quote character, use four single quotes in a row.

To force the very first letter in a date format to be capitalized, start the format string with a ^ (caret) symbol. For example:

{$ setDateTimeFormat "Spanish" "DDDD" "HH':'mm" $}

would produce the all-lowercase day of the week (e.g. lunes) while

{$ setDateTimeFormat "Spanish" "^DDDD" "HH':'mm" $}

would produce Lunes, which would be more correct at the beginning of a sentence. (In English, days of the week and month are always capitalized so this doesn't matter).

 

CityDesk Documentation -  Home


©Copyright 2001-2003 Fog Creek Software, Inc. All Rights Reserved.