Formatted output of tostring in datetime

Source: Internet
Author: User

Datetime. tostring ()There are four overload functions. Generally, it is the one with no parameters. However,Datetime. tostring (string format)More powerful, can output dates of different formats. The following lists some cases for your reference. SomeMsdnThe above is not listed.

1.YIndicates the year. It must be in lower case.Y, Uppercase y does not represent the year.

2.MIndicates the month.

3.DIndicates the date. Note:DIt does not mean anything.

4.HOrHIndicates the hour,HYes12Hour system,HYes24Hour.

5.MMinute.

6.SSecond. Note:SIt does not mean anything.

Format

Output

Example

Year

Y

7

String YY = datetime. Now. tostring ("Y-mm ")

YY = "7-05"

YY

07

String YY = datetime. Now. tostring ("YY-mm ")

YY = "07-05"

YyyOr moreY

1984

String YY = datetime. Now. tostring ("YYYY ");

YY = "2007"

Month

M

5.

String MON = datetime. parse ("1984-05-09") tostring ("yyyy-M ")

MON = "1984-5"

Mm

05.

String MON = datetime. parse ("1984-05-09") tostring ("mM")

MON = "05"

Mmm

If it is a Chinese version of the operating system, the output will be: May.

For an English operating system, enter the abbreviation of the first three letters of the month:May

String MON = datetime. parse ("2006-07-01"). tostring ("mmm ")

English version operating system:Jul

Chinese version Operating System: July

MmmmOr more m

If it is a Chinese version of the operating system, the output will be: May.

For an English operating system, enter the full number of months.

String MON = datetime. parse ("2006-07-01"). tostring ("mmm ")

English version operating system:July

Chinese version Operating System: July

Date or week

D

9

String dd = datetime. parse ("1984-05-09") tostring ("D ")

Dd = "9"

 

Dd

09

String dd = datetime. parse ("1984-05-09") tostring ("DD ")

Dd = "09"

Ddd

For the Chinese version of the operating system, the week, for example, Wednesday, will be output..

For an English operating system, the abbreviation of the week is output:

Wed

String dd = datetime. parse ("2006-07-01"). tostring ("DDD ")

English version operating system:Wed

Chinese operating system: Wednesday

DdddOr moreD

For the Chinese version of the operating system, the week, for example, Wednesday, will be output..

For an English operating system, the week is output, as shown in figure

Wednesday

String dd = datetime. parse ("2006-07-01"). tostring ("dddd ")

English version operating system:Wednesday

Chinese operating system: Wednesday

Hours

H

Hour range:1-12

String HH = datetime. Now. tostring ("H ");

HH = 8

HHOr moreH

Hour range:1-12

String HH = datetime. Now. tostring ("hh ");

HH = 08

H

Hour range:0-23

String HH = datetime. Now. tostring ("yyyy-H ");

HH = 2006-8

HHOr moreH

Hour range:0-23

String HH = datetime. Now. tostring ("yyyy-hh ");

HH = 2006-08

String HH = datetime. Pare ("18:00:00"). tostring ("yyyy-hh ");

HH = 2006-18

Minutes

M

6

String Mm = datetime. Now. tostring ("yyyy-mm-dd-M ");

Mm = "2006-07-01-6 ";

MmOr moreM

06

String Mm = datetime. Now. tostring ("yyyy-mm-dd-mm ");

Mm = "2006-07-01-06 ";

Seconds

S

6

String Mm = datetime. Now. tostring ("yyyy-mm-dd-s ");

Mm = "2006-07-01-6 ";

SSOr moreS

06

String Mm = datetime. Now. tostring ("yyyy-mm-dd-SS ");

Mm = "2006-07-01-06 ";

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.