DateTime将日期显示为01/01/0001 [英] DateTime shows the date as 01/01/0001

查看:43
本文介绍了DateTime将日期显示为01/01/0001的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这看起来像是一个愚蠢的问题,但是我在任何地方都找不到答案,我有点新手.日期时间显示为我推测的最短日期.例如:

Sorry if this seems as a stupid question, but I cannot find an answer anywhere and I am a bit of a newbie. DateTime shows to be what I surmised as the Min Date. For instance:

DateTime updatedDate = new DateTime();
outItem.AddDate = updatedDate.ToLongDateString();

输出结果是0001年1月1日.我已经尝试了很多类似的结果.我究竟做错了什么?

The output comes out to January 01, 0001. I've tried many variations of this with similar results. What am I doing wrong?

推荐答案

这取决于您所说的错误". new DateTime()确实具有与 DateTime.MinValue 相同的值.如果要当前时间,则应使用:

It depends on what you mean by "wrong". new DateTime() does indeed have the same value as DateTime.MinValue. If you want the current time, you should use:

DateTime updatedDate = DateTime.Now;

DateTime updatedDate = DateTime.UtcNow;

(第一个给您 local 时间,第二个给您 universal 时间. DateTime

(The first gives you the local time, the second gives you the universal time. DateTime is somewhat messed up when it comes to the local/universal divide.)

这篇关于DateTime将日期显示为01/01/0001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆