Appendix O : Date and Time Format Specifiers


A program uses date and time format specifiers to determine how dates and times are represented as strings. For example, the Date object’s ToString method returns a string representing a date and time. An optional parameter to this method tells the object whether to format itself as in 2/20/2004, 02.20.04 A.D or Friday, February 20, 2004 2:37:18 PM.

Visual Basic provides two kinds of specifiers that you can use to determine a date and time value’s format: standard format specifiers and custom format specifiers.

Standard Format Specifiers

A standard format specifier is a single character that you use alone to indicate a standardized format. For example, the format string d indicates a short date format (as in 2/20/2004).

The following table lists standard format specifiers that you can use to format date and time strings. The results depend on the regional settings on the computer. The examples shown in this table are for a typical computer in the United States.

Open table as spreadsheet

Specifier

Meaning

Example

d

Short date.

2/20/2004

D

Long date.

Friday, February 20, 2004

t

Short time.

2:37 PM

T

Long time.

2:37:18 PM

f

Full date/time with short time.

Friday, February 20, 2004 2:37 PM

F

Full date/time with long time.

Friday, February 20, 2004 2:37:18 PM

g

General date/time with short time.

2/20/2004 2:37 PM

G

General date/time with long time.

2/20/2004 2:37:18 PM

m or M

Month and date.

February 20

r or R

RFC1123 pattern. Formatting does not convert the time to Greenwich Mean Time (GMT), so you should convert local times to GMT before formatting.

Fri, 20 Feb 2004 14:37:18 GMT

s

Sortable ISO 8601 date/time.

2004-02-20T14:37:18

u

Universal sortable date/time. Formatting does not convert the time to universal time, so you should convert local times to universal time before formatting.

2004-02-20 14:37:18Z

U

Universal full date/time. This is the full universal time, not the local time.

Friday, February 20, 2004 9:37:18 PM

y or Y

Year and month.

February, 2004




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net