How can I get the user DateTime

G

Guest

Hi;

When I get a request how can I get the user's local DateTime? I can get
ultureInfo.CurrentUICulture.Calendar for a calendar but I don't see any way
to turn that in to a DateTime (although you would think that would be
possible).

Also, is there any way to set IE to have a different timezone than my system
to test this on my system (so IE is set to pacific time but my "server" is on
mountain time)?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
L

LosManos

hejdig.

Ge information about the client's (IE's) time through javascript and insert
this into a hidden field.
Look at this field by the next posting to find out whatever you need.
Normally time is incremented/decremented in whole hours and by comparing the
server's time and hope the client's clock is adjusted you could find out the
time zone. (If this is what you are looking for)
If there is any other way to find out the TZ for the client through
javascript please look into http://javascript.faqts.com/ . You could for
instance find the difference between the UTC and the local time through
javascript.

For setting different timezones client/server on the same machine. The
easiest way would be to borrow a machine from someone - anything that runs
your browsers would do. A slightly more expensive (time wise) solution
would be to install a virtual pc on the same machine.
Or use WMWares solutions where you run a Linux OS in a virtual machine. You
can still play around with the timezone just as easy.

HTH

/OF
 
G

Guest

I understand you need this information before postback, therefore you cannot
use javascript. You may use Request.UserLanguages to obtain user preffered
language

if (!IsPostBack)
{
const string DefaultLanguageCode = "en-GB";

string[] languages = Request.UserLanguages;
string code = DefaultLanguageCode;
System.Globalization.CultureInfo cultureInfo;

if (languages != null && languages.Length > 0)
{
code = languages[0];
}
}

Then the real deal begins. There is no standard function in ASP.NET to
retrive all timezones (but this feature will be available in the next version
3.0 of .NET). There is of course System.TimeZone class, but you can read just
the local, server zone information To populate all the timeones you could use
WinAPI - don't worry it's not difficult,
http://www.michaelbrumm.com/simpletimezone.html), then match language code
with timezone.

hope this helps
 
G

Guest

Hi;

For the UK that would work ok. But for the US (or Russia), there is a very
large number of timezones. Isn't there something in the request header that
lists the GMT offset of the requesting browser?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




Milosz Skalecki said:
I understand you need this information before postback, therefore you cannot
use javascript. You may use Request.UserLanguages to obtain user preffered
language

if (!IsPostBack)
{
const string DefaultLanguageCode = "en-GB";

string[] languages = Request.UserLanguages;
string code = DefaultLanguageCode;
System.Globalization.CultureInfo cultureInfo;

if (languages != null && languages.Length > 0)
{
code = languages[0];
}
}

Then the real deal begins. There is no standard function in ASP.NET to
retrive all timezones (but this feature will be available in the next version
3.0 of .NET). There is of course System.TimeZone class, but you can read just
the local, server zone information To populate all the timeones you could use
WinAPI - don't worry it's not difficult,
http://www.michaelbrumm.com/simpletimezone.html), then match language code
with timezone.

hope this helps
--
Milosz Skalecki
MCP, MCAD


David Thielen said:
Hi;

The problem with javascript is I need this information when creating the
page, not when processing the submit. So if they come to the page I need this
on first, no javascript has run yet and therefore there is no way to get the
info.

Doesn't this get passed in the header request somewhere?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
S

Steven Cheng[MSFT]

Hi Dave,

So far I haven't found any standard httpheader(most browser will use) to
send client-side timezone info. And yes, use timezone API to query the
timezone from a given language/culture is not quite easy.

IMO, I think you may consider such a workaround solution:

** create a helper server page in your application which embeded client
script to get the client time-zone offset info and postback to server.

** your server-side will get the timezone info and store it in
cache(session or profile) for the current user

** for each user, you may redirect it to the helper page first (if there is
no timezone info in the certain cache storage)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

I think at that time the Timezone inforamtion is not considered so critical
to include in http specification. Anyway, so far we haven't any better
means to directly get the accurate timezone info in the first http request
to our web page. Do you think using a help page may help? Also, you may
also put some AJAX script in your default page to collect such information
and update it to server-side(cache) without postback.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top