我有字符串05.03.2018,我需要将其转换为2018-03-05以将其发送到db。我尝试了DateTime.Parse() DateTime.Parse() DateTime.ParseExact()
但仍然转换为"05-Mar-2018 12:00:00 AM"
我甚至不知道为什么会有时间..
如何转换它? 感谢
答案 0 :(得分:1)
请尝试这个
string testDate = "05.03.2018";
DateTime dt = DateTime.ParseExact(testDate, "dd.MM.yyyy", CultureInfo.InvariantCulture);
string op = dt.ToString("yyyy-MM-dd");
答案 1 :(得分:0)
我相信
DateTime.Parse(yourstring).ToString("yyyy-MM-dd");
会起作用。