Error reason: because the date string cannot be converted normally.
Resolution code:
class Program { static void Main(string[] args) { //1, the correct way to write (without the symbols of the date string to convert the common date format, formatDate output results are: 2021-10-11) IFormatProvider ifp = new CultureInfo("zh-CN", true); string formatDate = DateTime.ParseExact("20211011", "yyyyMMdd", ifp).ToString("yyyy-MM-dd"); Console.WriteLine(formatDate); Console.ReadKey(); } }
Similar Posts:
- [Solved] java.lang.IllegalArgumentException: Cannot format given Object as a Date
- ValueError: day is out of range for month [How to Solve]
- ValueError: day is out of range for month [How to Solve]
- ora-01810 format code appears twice
- Using Vue + Axios: axios.post error: request failed with status code 400 is one of the solutions
- [How to Solve] Failed to convert value of type ‘java.lang.String’ to required type ‘java.util.Date’;
- On the non thread safety problem of simpledateformat and its solution
- Get the time value from the database and report an error: Java sql. Timestamp cannot be cast to java. lang.Long
- TypeError: strptime() argument 1 must be str, not bytes
- Springboot uses the Datetimeformat (pattern = “yyyy MM DD HH: mm: SS”) annotation to automatically convert the string to date type error