我已经将DateTime设置为返回当前时间,这工作得很好,但由于需要在主类中有一个私有的静态(它是调度作业-我正在使用quartz-scheduler),当程序第一次运行时,我得到了正确的DateTime,但正如你所知道的,每次我得到相同的DateTime旧值之后,它的静态字段都是一样的。
我的问题是,有没有办法在每次程序运行时获得新的DateTime?
private static DateTime currentDateTime= DateTime.Today;
谢谢。
更新
当我发出HTTP WEB请求时,currentDateTime在第一次运行后被缓存,因此我必须使用以下命令缓存请求的策略
HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
webRequest.CachePolicy = noCachePolicy;发布于 2019-12-16 19:59:06
据我所知,问题是您将值设置为1。为什么不试着使它成为属性,然后当您尝试获取数据时
private static DateTime currentDateTime{
get
{
return DateTime.Today;
}
}发布于 2019-12-16 19:58:25
贴一个>,有你很好。
private static DateTime currentDateTime=> DateTime.Today;https://stackoverflow.com/questions/59356084
复制相似问题