<cDateTime>.ToStringFormat

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > BuiltIn Functions > Date and Time > cDateTime > cDateTime_Methods >

<cDateTime>.ToStringFormat

 

Description

 

Return current date and time in a string form using special placeholdrs.

 

Syntax

 

s = <cDateTime>.ToStringFormat(strFormat)

 

Returns

 

String

 

Parameters

 

Name

Type

Optional

Meaning

strFormat

String

yes

Specify style format string and return the date/time in that format, supporting placeholders like yyyy, MM, dd, HH, mm, ss, fff, tt, dddd, MMM, etc.

 

Warning: all placeholders are case sensitive

 

Supported Format Tokens

Token

Meaning

Example

yyyy

4-digit year

2025

yy

2-digit year

25

MMMM

Full month name

August

MMM

Abbreviated month name

Aug

MM

Month (01-12)

08

M

Month (1-12)

8

dddd

Full day of week name

Sunday

ddd

Abbreviated day of week name

Sun

dd

Day of month (01-31)

07

d

Day of month (1-31)

7

HH

Hour in 24-hour format (00-23)

14

H

Hour in 24-hour format (0-23)

14

hh

Hour in 12-hour format (01-12)

02

h

Hour in 12-hour format (1-12)

2

mm

Minute (00-59)

09

m

Minute (0-59)

9

ss

Second (00-59)

05

s

Second (0-59)

5

fff

Milliseconds (000-999)

073

tt

AM/PM

AM

t

A/P

A

 

1.Locale‑aware names: "dddd" / "ddd" / "MMMM" / "MMM" returns localized day/month strings from Windows.

2.Literal text: single quotes wrap verbatim text; doubled '' becomes a single quote (like .NET).

3.Escapes: \ makes the next character literal (e.g., H\h m\m ⇒ 13h 05m).

4.AM/PM rules: 00:00:00 → 12:00:00 AM; 12:00:00 → 12:00:00 PM.

 

 

 

Remarks

 

Restrictions

 

See also

 

Examples

 

Uses "Console"
 
' Create an object with current date and time
Dim dt As New cDateTime
 
' Displays the current time and date
Printl dt.toStringFormat("yyyy/MM/dd HH:mm")
Printl dt.toStringFormat("yyyy-MM-dd HH:mm:ss.fff")
Printl dt.toStringFormat("dd/MM/yyyy 'alle' HH:mm 'ora locale'")
Printl dt.toStringFormat("dddd, MMMM d, yyyy"
Printl dt.toStringFormat("hh:mm tt") & "  (12-hour with AM/PM)" 
Printl dt.toStringFormat("H\h m\m s\s") & "  (escaped unit letters)" 
Printl dt.toStringFormat("yyyy-'Q'Q (literal ' quotes: '' )"
Printl dt.toStringFormat("ddd MMM dd HH:mm:ss yyyy")
 
WaitKey