In designing web applications especially using Asp.net MVC4 c#, once I use
private DateTime currentDateTime = DateTime.Now;
somewhere in my code and save currentDateTime in a database; and then, I deploy my application in the web,
What will be the value of currentDateTime?
a. DateTime of the browser/computer which opened my application (timezone issue)
b. DateTime of the server in which I deployed my application (all values are in under one timezone)
Sorry, but I am just starting in web applications so this one confuses me. Hope you can clarify it to me. Thanks.
The property UtcNow of the DateTime class returns the current date and time of the machine running the code, expressed in UTC format. UTC is a universal format to represent date and time as an alternative to local time. Also known as the GMT+00 timezone.
Mind that datetime. today() and datetime. now() return the local time, not the UTC time, so applying .
It also sets Kind to Utc . DateTime. Now alters the Ticks value to what it would be if it was your time of day in the GMT time zone.
It tends to be between 0.5 and 15 milliseconds. As a result, repeated calls to the Now property in a short time interval, such as in a loop, may return the same value.
The value will the local time on the server.
However, I would strongly recommend using Universal Coordinated Time (UTC) eg, DateTime.UtcNow
, it makes reasoning about date times much simpler and will mean that you will be able to host your application anywhere in the world without adverse affects.
The ASP.Net code is executing on the server, so it will be server time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With