. NET in DateTime.Now.ToString display milliseconds:
DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss.fff")
Other formatted strings for DateTime.Now.ToString:
| formatting strings |
Interpretation |
Example |
| D |
Long Date |
Thursday, April 2008 |
| D |
Short Date |
04/10/2008 |
| F |
Full Date Long |
Thursday, April 2008 06:30:00 |
| F |
Full date Short |
Thursday, April 2008 06:30 |
| G |
General Long |
04/10/2008 06:30:00 |
| G |
General Short |
04/10/2008 06:30 |
| M |
Month |
April 10 |
| O |
ISO 8601 |
2008-04-10t06:30:00.0000000 |
| R |
RFC 1123 |
Thu, APR 06:30:00 GMT |
| S |
Sortable |
2008-04-10t06:30:00 |
| T |
Long time |
06:30:00 |
| T |
Short time |
06:30 |
| U |
Universal full |
Wednesday, April 2008 22:30:00 |
| U |
Universal sortable |
2008-04-10 06:30:00z |
| Y |
Year Month |
April |
| Yy-mm-dd |
Custom |
08-04-10 |
| YYYY MMMM DD |
Custom |
April 08 |
| YY-MMMM-DD DDD |
Custom |
08-apr-8 Tue |
| yyyy-m-d dddd |
Custom |
2008-4-8 Tuesday |
| Hh:mm:ss T Z |
Custom |
04:03:05 P-7 |
| H:MM:SS TT ZZ |
Custom |
4:03:05 PM-07 |
| HH:MM:SS TT ZZ |
Custom |
16:03:05 PM-07 |
| Hh:m:s TT zzz |
Custom |
16:3:5 pm-07:00 |
The above source ReSharper.
Of course, you can also use The properties provided by the DateTime class (for example: DateTime.Now.Year) and methods (such as: DateTime.Now.ToShortDateString ()).
The above content is relatively simple, but encountered some needs are very useful ~
. DateTime.Now.ToString formatted strings in net