How to use mnemonic in formatting rules of numbers and dates in .net
This article mainly introduces how to use the number and date formatting rules in. Net. The introduction in the article is very detailed and has certain reference value. Interested friends must read it!
Format can be performed by string.Format method or directly by xx.ToString("") method. Format rules are not easy to remember, this article through simple words, can help you remember these rules
1. digitally formatted
The rules are simple: a letter indicating the type of formatting followed by an optional number indicating the number of decimal places to retain.
There are only a few letters: C, D, E, F, G, N, P, R, X. Case is universal.
2. DateTime formatting
2013-05-18 13:09:24.211 +8:00
The year is y:
Y-year units
Last two digits of yy year
yyy year last three digits
yy four-digit year
yy add 0 before the four-digit year
Large M indicates month, less than 10 without leading 0
MM table month, less than October to add leading 0
Three M month names. You have to remember them for short.
Four M month names, use the full name, don't forget
A d means what number it is, no 0 before the 10th
dd indicates the number. Add 0 before 10.
ddd stands for day of the week, so remember the abbreviation.
dddd indicates the day of the week. You must use your full name and not forget it.
Lowercase h represents hour, decimal system can not forget
One h cannot be preceded by a zero, two h's preceded by a zero if necessary
Size H meter hour, 24 base to remember
One H cannot be preceded by a zero, two H's preceded by a zero if necessary.
Lowercase m for minutes, one not necessarily preceded by a zero, two if necessary
Lower-case s for seconds, one not necessarily preceded by a zero, two if necessary.
f is a tenth of a second.
ff stands for hundredth of seconds
fff represents milliseconds
ffff represents tenths of a millisecond
and so on to 7f.
There is a difference between upper and lower case
If it's 0, ignore upper-case and have lower-case
And two that aren't used very often.
gg stands for morning and afternoon
k and z mean time zone.
The above is ". Net numbers and date formatting rules mnemonic how to use" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!