1. 程式人生 > >The specified value "2019-1-2" does not conform to the required format, "yyyy-MM-dd"

The specified value "2019-1-2" does not conform to the required format, "yyyy-MM-dd"

問題:

在cshtml中轉換的日期格式錯誤,前端報錯:The specified value "2019-1-2" does not conform to the required format, "yyyy-MM-dd"

 

導致原因:

由於時間格式沒有完全匹配,"yyyy-MM-dd"應該對應"2019-01-02"

 

修改程式碼:

string.Format("{0:yyyy-MM-dd}", DateTime.Now);