1. Convert the date format to a string:
String timestr = DT. tow.datestring ();
Or string timestr = DT. tow.timestring ();
Or string timestr = DT. tostring ("yyyymmdd ");
Note: In custom format conversion, yyyy indicates the year, for example, 2008 or YY indicates the year, for example, 08 years, And mm indicates the month, DD indicates the day, and HH indicates the hour, in lower case, MM indicates minutes, and SS indicates seconds.
2. Code for converting string format to date format:
Datetime dt = convert. todatetime ("2008-06-30 ");
The character string format must be fixed. If it is not the form written above, you must use the string processing function to modify the character string!
Supplement:
Accurate to minutes and seconds
Datetime dt = convert. todatetime ("11:11:10 ");
String timestr = DT. tostring ("yyyymmddhhmmss"); // hh: 12: 24
1. Convert the date format to a string:
String timestr = DT. tow.datestring ();
Or string timestr = DT. tow.timestring ();
Or string timestr = DT. tostring ("yyyymmdd ");
Note: In custom format conversion, yyyy indicates the year, for example, 2008 or YY indicates the year, for example, 08 years, And mm indicates the month, DD indicates the day, and HH indicates the hour, in lower case, MM indicates minutes, and SS indicates seconds.
2. Code for converting string format to date format:
Datetime dt = convert. todatetime ("2008-06-30 ");
The character string format must be fixed. If it is not the form written above, you must use the string processing function to modify the character string!
Supplement:
Accurate to minutes and seconds
Datetime dt = convert. todatetime ("11:11:10 ");
String timestr = DT. tostring ("yyyymmddhhmmss"); // hh: 12: 24