I'm developing an application in Visual Studio using C#. When I create a new instance of an object I want to attach the current date and time to it. Using DateTime.Now
the time is off by one hour.
I presume its a time-zone or daylight saving issue. I tried calling System.Globalization.CultureInfo.CurrentCulture.ClearCachedData()
right before DateTime.Now
but got the same result. How do I resolve this?
您应该使用DateTime.UtcNow
而不是DateTime.Now
来避免时区问题( DateTime.Now
使用服务器的时区),然后您可以将UTC值转换为用户的时区。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.