From Clomosy Docs
ClomosyAdmin (talk | contribs) No edit summary |
ClomosyAdmin (talk | contribs) No edit summary |
||
Line 81: | Line 81: | ||
<h2> See Also </h2> | <h2> See Also </h2> | ||
* [[System_Library#Date_and_Time_Functions | Date and Time Functions]] | * [[System_Library#Date_and_Time_Functions | Date and Time Functions]] | ||
{{#seo:|title=FormatDateTime Using in Clomosy - Clomosy Docs}} | |||
{{#seo:|description=Learn how to use the FormatDateTime function in Clomosy to format TclDateTime values into customized date and time strings for display or processing.}} | {{#seo:|description=Learn how to use the FormatDateTime function in Clomosy to format TclDateTime values into customized date and time strings for display or processing.}} |
Latest revision as of 15:04, 24 December 2024
function FormatDateTime(const Format: string; DateTime: TclDateTime):string;
The FormatDateTime function provides rich formatting of a TclDateTime value DateTime into a string. Formatting is defined by the Format string. The Format string can comprise a mix of ordinary characters (that are passed unchanged to the result string), and data formatting characters. This formatting is best explained by the example code.
The following (non-Asian) formatting character strings can be used in the Formatting string:
- y = Year last 2 digits
- yy = Year last 2 digits
- yyyy = Year as 4 digits
- m = Month number no-leading 0
- mm = Month number as 2 digits
- mmm = Month using ShortDayNames (Jan)
- mmmm = Month using LongDayNames (January)
- d = Day number no-leading 0
- dd = Day number as 2 digits
- ddd = Day using ShortDayNames (Sun)
- dddd = Day using LongDayNames (Sunday)
- ddddd = Day in ShortDateFormat
- dddddd = Day in LongDateFormat
- c = Use ShortDateFormat + LongTimeFormat
- h = Hour number no-leading 0
- hh = Hour number as 2 digits
- n = Minute number no-leading 0
- nn = Minute number as 2 digits
- s = Second number no-leading 0
- ss = Second number as 2 digits
- z = Milli-sec number no-leading 0s
- zzz = Milli-sec number as 3 digits
- t = Use ShortTimeFormat
- tt = Use LongTimeFormat
- am/pm = Use after h : gives 12 hours + am/pm
- a/p = Use after h : gives 12 hours + a/p
- ampm = As a/p but TimeAMString,TimePMString
- / = Substituted by DateSeparator value
- : = Substituted by TimeSeparator value
Example
var myDate : TDateTime; { myDate = '20.02.2023 12:24:26'; ShowMessage('d.m.y = '+FormatDateTime('d.m.y', myDate)); ShowMessage('dd.mm.yy = '+FormatDateTime('dd.mm.yy', myDate)); // Use short names for the day, month, and add freeform text ('of') ShowMessage('ddd d of mmm yyyy = '+FormatDateTime('ddd d of mmm yyyy', myDate)); // Use long names for the day and month ShowMessage('dddd d of mmmm yyyy = '+FormatDateTime('dddd d of mmmm yyyy', myDate)); // Use the ShortDateFormat settings only ShowMessage('ddddd = '+FormatDateTime('ddddd', myDate)); // Use the LongDateFormat settings only ShowMessage('dddddd = '+FormatDateTime('dddddd', myDate)); ShowMessage('c = '+FormatDateTime('c', myDate)); }
Output:
d.m.y = 20.2.23
dd.mm.yy = 20.02.23
ddd d of mmm yyyy = Mon 20 of Feb 2023
dddd d of mmmm yyyy = Monday 20 of February 2023
ddddd = 20.02.2023
dddddd = 20 February 2023 Monday
c = 20.02.2023 12:24:26