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" |
Yyy or more y |
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: Jul Chinese version Operating System: July |
MMMM or 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: 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 a Chinese operating system, the week, for example, Wednesday, is displayed .. For an English operating system, the abbreviation of the week is output: Wed |
String dd = DateTime. Parse ("2006-07-01"). ToString ("ddd ") English version: Wed Chinese operating system: Wednesday |
Dddd or more d |
For a Chinese operating system, the week, for example, Wednesday, is displayed .. 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: Wednesday Chinese operating system: Wednesday |
Hours |
H |
Hour range: 1-12 |
String hh = DateTime. Now. ToString ("h "); Hh = 8 |
Hh or more h |
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 |
HH or more H |
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 "; |
Mm or more m |
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 "; |
Ss or more s |
06 |
String mm = DateTime. Now. ToString ("yyyy-MM-dd-ss "); Mm = "2006-07-01-06 "; |