Link to home
Start Free TrialLog in
Avatar of RayT
RayTFlag for United States of America

asked on

Retrieve Client's Date & Time

Is there a way to retrieve the client's date and time using ASP.NET 2.0?
Avatar of Pratima
Pratima
Flag of India image

ASKER CERTIFIED SOLUTION
Avatar of gnoon
gnoon
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dim strD As String = Request("cdatetime") '^^
Avatar of RayT

ASKER

Gnoon,

I tried your code and it returns a time that is 5 hours ahead of my time.  I was expecting to see the same date and time that is on my PC.

How do I get it to do that?
I guess it's converted to UTC while parsing because we does not provide any time zome information in the format for the parsing.
Furthermore, as I see your time zone above it is GMT-05:00. Also, en-US (as we used it for parsing) is GMT-05:00. So, I'm not sure here which one is the cause of 5 hours ahead.

I think it's about DateTimeStyles of parsing. Unfortunately, I do not have the environment to test it.
I think using AssumeLocal option is forcing it to not convert to UTC again (because the javascript already did it).

Try
     clientDateTime = System.DateTime.ParseExact(strD, "ddd, dd MMM yyyy HH:mm:ss 'UTC'", culture, _
                  DateTimeStyles.AssumeLocal)
Catch
End Try
Avatar of RayT

ASKER

Thanks