How to use mnemonic words based on number and date formatting rules in. Net

Source: Internet
Author: User

You can use the string. Format method or the xx. ToString ("") method for formatting. Formatting rules are not easy to remember. This article uses simple words to help you remember these rules 
1. digit formatting
The rule is simple. It is a letter indicating the type of formatting followed by an optional number indicating the number of decimal places to be retained.
There are just a few letters: C, D, E, F, G, N, P, R, and X are common cases.

2. Format DateTime
13:09:24. 211 + 8: 00
The year is y:
One y year
The last two digits of the year yy
Last three digits of yyy year
Yyyy four-digit year
Yyyyy: Add 0 before the four-digit year

Month of a large M Table, less than 10 without leading 0
MM table month. If it is less than January 1, October, a leading 0 is required.
Name of three M months.
Four M month names.

A d indicates the number of digits, and 0 is not added before 10.
Dd indicates the number of digits. Add 0 before the 10 th.
Ddd indicates the day of the week.
Dddd indicates the day of the week.

The hour in lower case h table, which is in 12 hexadecimal format cannot be forgotten
One h cannot be preceded by 0, and two h must be preceded by 0 if necessary.
H-sized table hours, which must be in the 24-digit notation
One H cannot be preceded by 0, and two H must be preceded by 0 if necessary.

Lowercase m Table minutes, one does not need to lead 0, two do not need to lead 0 if necessary
Lowercase s indicates the second, one does not need to lead 0, and two do not need to lead 0 if necessary

F indicates a tenth of seconds.
Ff indicates the percentage of seconds
Fff indicates the number of milliseconds
Ffff indicates a tenth of milliseconds.
And so on to 7f.
Differences between uppercase and lowercase letters
If the value is 0, the values in uppercase and lowercase are ignored.

Two others are not commonly used.
Gg indicates the last afternoon
K and z indicate the time zone.

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.