Server Time

  • Thread starter Thread starter brian
  • Start date Start date
B

brian

I have an intranet set up and when the user clicks a
button I want the time on the server to appear in the
text box.

By reading through the post I found many that said
DateTime.Now.Hour.ToString should bring back the server's
time. But it brings back the time on my local machine.
From my research it sounded like to get local time on the
client you needed to use JaveScript.

Can someone clarify and help me get the time on the
servers station?

Thanks
 
Hi Brian,

Make sure that the call to DateTime.Now.Hour.ToString is being run on the
server side. If it is embedded on the page in a script tag without the
runat="server" attribute, then it might be running client-side.

To make sure the code is running server side, try putting it in code behind.

I notice that you're also only grabing the hour. Unless you are in a
differnet time zone or your system clocks are drastically off, the hour
should match on both machines. To test, try setting the machine clocks to
somethign drastically different and grab the DateTime.Ticks property and
compare.

HTH,
Mark Jen [MSFT]
 
Back
Top