vb.net date-time format conversion (Format function)

Source: Internet
Author: User
Tags locale month name net time
VB.net time in the system

Dim datestr as String = ""

datestr = Format (now (), "Yyyy/mm/dd h:mm:ss ffff")

User-defined date/time format (Format function)

The following table shows the characters you can use to create a user-defined date/time format. Unlike earlier versions of Visual Basic, these format characters are case-sensitive.

character Description

(:)

The time separator. In some locales, you can use other characters to represent the time separator. The time separator separates hours, minutes, and seconds when formatting time values. The actual character used as the time separator in the formatted output is determined by the LocaleID value of the system.

(/)

The date separator. In some locales, you can use other characters to represent a date separator. The date separator separates day, month, and year when formatting date values. The actual characters used as date separators in the formatted output are determined by your locale settings.

(%)

Used to indicate that characters should be read in one-letter format, regardless of the letter followed. Also used to indicate that a single letter format should be read in a user-defined format. For more detailed information, see below.

D

Displays the day as a number with no leading zeros (for example, 1). If this is the only character in the user-defined number format, use %d.

DD

Displays the day as a number with a leading zero (for example, 01).

DDD

Displays the day as an abbreviated form (for example, Sun).

dddd

Displays the day as a full name (for example, Sunday).

M

Displays the month as a number without a leading zero (as indicated in January as 1). If this is the only character in the user-defined number format, use %m.

MM

Displays the month as a number with a leading zero (for example, 01/12/01).

MMM

Displays the month as an abbreviated form, such as a few months.

MMMM

Displays the month as the full month name (for example, January).

GG

Displays the era/era string (for example, A.D.)

h

Use a 12-hour system to display hours as numbers with no leading zeros (for example, 1:15:15 PM). If this is the only character in the user-defined number format, use %h.

hh

Use a 12-hour system to display hours as numbers with leading zeros (for example, 01:15:15 PM).

H

Use a 24-hour system to display hours as a number without a leading zero (for example, 1:15:15). If this is the only character in the user-defined number format, use %H.

HH

Use a 24-hour system to display hours as numbers with leading zeros (for example, 01:15:15).

m

Displays the minute as a number without a leading zero (for example, 12:1:15). If this is the only character in the user-defined number format, use %m.

mm

Displays the minute as a number with a leading zero (for example, 12:01:15).

s

Displays the second as a number without a leading zero (for example, 12:15:5). If this is the only character in the user-defined number format, use %s.

SS

Displays the second as a number with a leading zero (for example, 12:15:05).

F

Displays the decimal part of the second. For example,FF will display exactly 1% seconds, and FFFF will be displayed exactly to one out of 10,000 seconds. You can use up to seven F symbols in a user-defined format. If this is the only character in the user-defined number format, use %f.

T

Use a 12-hour system and display uppercase A for any hour prior to noon, with an uppercase P for any hour between noon and 11:59 p.m. If this is the only character in the user-defined number format, use %t.

TT

For a 12-hour locale, show uppercase AM for any hour before noon, with uppercase PM for any hour between noon and 11:59 p.m.

No characters are displayed for regional settings that use a 24-hour system.

y

Displays the year (0-9) as a number with no leading zeros. If this is the only character in the user-defined number format, use %y.

yy

Displays the year in two-digit format with a leading zero, if applicable.

yyy

Displays the year in four-bit number format.

yyyy

Displays the year in four-bit number format.

Z

Displays the time zone offset (for example, 8) without a leading zero. If this is the only character in the user-defined number format, use %z.

ZZ

Displays the time zone offset with a leading zero (for example, 08)

zzz

Displays the full time zone offset (for example, -08:00)

Sample

The following examples describe the user-defined date and time formats for December 7, 1958, 8:50 PM, seconds:

format show

M/d/yy

12/7/58

d-mmm

7-dec

D-mmmm-yy

7-december-58

D MMMM

7 December

td>

MMMM yy

December,

hh:mm tt

08:50 PM

H:mm:ss t

8:50:35 p

h:mm

20:50

H:mm:ss

20:50:35

m/d/yyyy h:mm

12/7/1958 20:50

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.