From Clomosy Docs
No edit summary |
ClomosyAdmin (talk | contribs) No edit summary |
||
| (4 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert"> | |||
function FormatDateTime(const Format: string; DateTime: TclDateTime):string; | |||
</div> | |||
The FormatDateTime function provides rich formatting of a TclDateTime value DateTime into a string. Formatting is defined by the | 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.<br> | ||
The following (non-Asian) formatting character strings can be used in the Formatting string: | The following (non-Asian) formatting character strings can be used in the Formatting string:<br> | ||
: | :<b>y</b> = Year last 2 digits | ||
: | :<b>yy</b> = Year last 2 digits | ||
: | :<b>yyyy</b> = Year as 4 digits | ||
:<b>m</b> = Month number no-leading 0 | |||
:<b>mm</b> = Month number as 2 digits | |||
:<b>mmm</b> = Month using ShortDayNames (Jan) | |||
:<b>mmmm</b> = Month using LongDayNames (January) | |||
: | :<b>d</b> = Day number no-leading 0 | ||
: | :<b>dd</b> = Day number as 2 digits | ||
: | :<b>ddd</b> = Day using ShortDayNames (Sun) | ||
: | :<b>dddd</b> = Day using LongDayNames (Sunday) | ||
:<b>ddddd</b> = Day in ShortDateFormat | |||
:<b>dddddd</b> = Day in LongDateFormat | |||
:<b>c</b> = Use ShortDateFormat + LongTimeFormat | |||
:<b>h</b> = Hour number no-leading 0 | |||
:<b>hh</b> = Hour number as 2 digits | |||
:<b>n</b> = Minute number no-leading 0 | |||
:<b>nn</b> = Minute number as 2 digits | |||
:<b>s</b> = Second number no-leading 0 | |||
:<b>ss</b> = Second number as 2 digits | |||
:<b>z</b> = Milli-sec number no-leading 0s | |||
:<b>zzz</b> = Milli-sec number as 3 digits | |||
:<b>t</b> = Use ShortTimeFormat | |||
:<b>tt</b> = Use LongTimeFormat | |||
: | :<b>am/pm</b> = Use after h : gives 12 hours + am/pm | ||
: | :<b>a/p</b> = Use after h : gives 12 hours + a/p | ||
: | :<b>ampm</b> = As a/p but TimeAMString,TimePMString | ||
: | :<b>/</b> = Substituted by DateSeparator value | ||
: | :<b>:</b> = Substituted by TimeSeparator value | ||
: | |||
<b>Example</b><br> | |||
<pre> | |||
var | |||
myDate : TDateTime; | |||
{ | |||
myDate = '20.02.2023 12:24:26'; | |||
myDate : TDateTime; | |||
myDate | |||
ShowMessage('d.m.y = '+FormatDateTime('d.m.y', myDate)); | ShowMessage('d.m.y = '+FormatDateTime('d.m.y', myDate)); | ||
ShowMessage('dd.mm.yy = '+FormatDateTime('dd.mm.yy', myDate)); | ShowMessage('dd.mm.yy = '+FormatDateTime('dd.mm.yy', myDate)); | ||
// Use short names for the day, month, and add freeform text ('of') | // 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)); | ShowMessage('ddd d of mmm yyyy = '+FormatDateTime('ddd d of mmm yyyy', myDate)); | ||
// Use long names for the day and month | // Use long names for the day and month | ||
ShowMessage('dddd d of mmmm yyyy = '+FormatDateTime('dddd d of mmmm yyyy', myDate)); | ShowMessage('dddd d of mmmm yyyy = '+FormatDateTime('dddd d of mmmm yyyy', myDate)); | ||
// Use the ShortDateFormat settings only | // Use the ShortDateFormat settings only | ||
ShowMessage('ddddd = '+FormatDateTime('ddddd', myDate)); | ShowMessage('ddddd = '+FormatDateTime('ddddd', myDate)); | ||
// Use the LongDateFormat settings only | // Use the LongDateFormat settings only | ||
ShowMessage('dddddd = '+FormatDateTime('dddddd', myDate)); | ShowMessage('dddddd = '+FormatDateTime('dddddd', myDate)); | ||
ShowMessage('c = '+FormatDateTime('c', myDate)); | ShowMessage('c = '+FormatDateTime('c', myDate)); | ||
} | |||
</pre> | |||
<b>Output:</b><br> | |||
<div class="alert alert-success" role="alert" data-bs-theme="light"> | |||
d.m.y = 20.2.23<br> | |||
dd.mm.yy = 20.02.23<br> | |||
ddd d of mmm yyyy = Mon 20 of Feb 2023<br> | |||
dddd d of mmmm yyyy = Monday 20 of February 2023<br> | |||
ddddd = 20.02.2023<br> | |||
dddddd = 20 February 2023 Monday<br> | |||
c = 20.02.2023 12:24:26 | |||
</div> | |||
<h2> See Also </h2> | |||
* [[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.}} | |||
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