DateTime.now.tostring ("YYYYMMDD") The result is 2006-03-16

xiaoxiao2021-03-13  203

Today I am using DateTime.now.tostring ("YYYY / MM / DD") result is 2006-03-16 instead of I want 2006/03/16, I will not be depressed. Later, I used a method to solve: DateTime.now.toString ("YYYY / MM / DD"). Replace ("-", "/"), this method can solve the problem (afterwards, this method is not used) However, it feels that it is always very awkward. Later, I would like to teach Han Lei's boss. It happens that he has encountered the same problem. The reason is that this method is directly in the date format of the system, so it will appear here. This inexplicable basics, the solution is to enable the second parameters of DateTime.toString (), ignore the system time format setting:

DateTime.now.toString ("YYYY / MM / DD", System.globalization.DatetimeFormatinfo.invariantIntinfo);

转载请注明原文地址:https://www.9cbs.com/read-129173.html

New Post(0)