jE ccA jE ccA - 1 year ago 125
ASP.NET (C#) Question

How to get the current time in server side?

I'm using mvc3.


(PC1) as server side or where I publish my project
(PC2) as client or where I am using my current PC
. In
the current time is
10:00 AM
and in
01:00 PM
with the same or different date/s. I have a button in my veiw
for getting the time of the
after i click the button.

So far I tried the code
in controller but it is getting what the current time in my current PC?.
Not sure about this one

How to solve this kind of problem?

Answer Source

Use DateTime.UtcNow() at client and server while saving the date and time. When you need to show date on your UI convert it to specific time zone using TimeZoneInfo.ConvertTimeFromUtc

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download