时间:2019-03-17 标签:c#asp.netDateTimecached
我在类上有一个字段,应该正确设置当前日期:
private static DateTime Today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
然后我根据日期执行不同的逻辑。 问题是它可以在本地运行,但不能在实时服务器上运行。 例如,如果日期是 5 日,则将执行 4 日的逻辑,除非我触摸 web.config 或更新 dll。所以我认为这是一个缓存问题,但为什么呢?我根本不缓存日期。 我没有使用 DateTime.Today 因为我认为这就是问题所在......
I've got a field on a class that should set the current date correctly:
private static DateTime Today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
And then I'm performing different logic based on the day.
The problem is that it works locally but it won't work on the live server.
So for example if the date is the 5th then the logic of the 4th will be performed, unless I touch the web.config or I update the dlls. So I assume it is a cache problem, but why? I'm not caching the date at all.
I did not use the DateTime.Today because I thought that was the problem...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个
静态
字段。每个 AppDomain 都会初始化一次。
That's a
static
field.It is initialized once per AppDomain.
我不知道你想做什么,但对我来说,你似乎想要当前的一天,但没有时间。你可以使用这个
I dont know what you want to do, but for me it looks like that you want the current Day without the time. You can get this using
是什么让你这么认为?
DateTime.Today 属性
Today
是一个静态变量,每个域仅设置一次What made you think that?
DateTime.Today Property
Today
is a static variable and is set only once per domain