473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can I get the user DateTime

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
Oct 26 '06 #1
7 6195
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

"David Thielen" wrote
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)?

Oct 26 '06 #2
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
Oct 26 '06 #3
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" wrote:
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

Oct 27 '06 #4
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" wrote:
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" wrote:
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
Oct 27 '06 #5
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.

Oct 27 '06 #6
I can't find anything either. It's amazing that they haven't added that to
the standard request header yet...

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

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


"Steven Cheng[MSFT]" wrote:
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.

Oct 27 '06 #7
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.

Oct 27 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nemo | last post by:
I have problem to get my dates from my user control. The problems is that the datetimes sets after when I get the values from my aspx page. Here is how my user control lock likes. private...
5
by: David C. Barber | last post by:
I'm trying to determine which user has locked a given record from VB6. I know I can use sp_lock and sp_who, and match up the data to determine which users have locked records in my database,...
3
by: teddysnips | last post by:
In the script below is the DDL to create some tables and a UDF. What I'm interested in is the UDF at the end. Specifically, these few lines: --CLOSE OTRate --DEALLOCATE OTRate ELSE --...
0
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. ...
1
by: Green | last post by:
Hi, All I need to dynamically load a user control and change some properties on the user control, and display in the aspx page. Unfortunately I failed, nothing appears. Please help me look at,...
1
by: Asad | last post by:
Hi, I was wondering how I can find out the time user takes on an aspx page before hitting a submit button. Since there is that whole server-side vs. client-side issue, I was thinking I can store...
3
by: Raterus | last post by:
Hi, I have a business object that exposes a DateTime object to my presentation layer. Usually this is filled with a valid date, but sometimes it is empty (and stored as 1/1/1900 as it is a...
0
by: Matt | last post by:
Have this ASPNET Applcation on dev server. On WindowsAuthentication_OnAuthenticate Getting the user id from database and matching with windows auth user id, if match assign to mUserIdentity get...
2
by: Mark | last post by:
Hi. I am making a user control right now, and it looks something like this: <script runat="server"> public string SelectCommand { set { // see below for why the following line is here.
1
by: Tamer Ibrahim | last post by:
Hi, I'm trying to validate user input date using range validator on a text box . This code is throwing this exception "The value 'DateTime.Now;' of the MaximumValue property of 'rvQDate'...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.