调用toString(QUOT; YYYY-MM-DD")会导致错误的日期格式 [英] Calling ToString("YYYY-mm-dd") results in wrong date format
问题描述
我有一个构造函数,它接受一个的DateTime
目标:
I've got a constructor which takes a DateTime
object:
public Report(DateTime date, string start = "0", string end = "0")
{
Logger.Info("Creating a new Report...");
StartTime = start;
EndTime = end;
Date = date.ToString("YYYY-mm-dd");
SetStartEndTimes();
Logger.Info("Report Created");
}
现在,这是工作的罚款短短3天前。不过,我今天回来,休息了,这是我看到的结果:
Now, this was working fine just 3 days ago. However, I come back today, after a break, and this is the results I'm seeing:
正如你所看到的,在传递的日期是正确的。然而,格式后,事实并非如此。同样,这个工作我休息前。我回来了,我得到这个。我缺少的东西吗?它为什么会从一开始工作后的格式,以便正确?
As you can see, the date being passed in is right. However, after the format, it is not. Again, this worked before my break. I come back, and I get this. Am I missing something? Why would it format so incorrectly after working since the beginning?
修改
多谢你们。在搞砸了部分是希望通过在以前的版本源头控制,这个工作。或者,也许我想象它的工作。我不知道。但它已经这样了约3个月
Thanks guys. The messed up part is looking through the source control at previous versions, this worked. Or maybe I imagined it working. I don't know. But it's been this way for about 3 months.
推荐答案
的年份必须是小写字母和月份大写的:
Year must be lowercase and month uppercase:
Date = date.ToString("yyyy-MM-dd"); // btw, lowercase mm means minutes
这篇关于调用toString(QUOT; YYYY-MM-DD")会导致错误的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!