473,289 Members | 1,884 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,289 software developers and data experts.

Get DateTimeFormatInfo for user?

I would like to format dates etc in the format that the user browsing the
page would prefer according to his language setting. The DateTimeFormatInfo
class provides all the information I need, but how do I get an instance of
it (or something else that has the info)?

Using DateTimeFormatInfo.Current doesn't work. It gives me the server
settings.
Using HttpRequest.UserLanguages to create a culture doesn't work either. The
language I get from that collection doesn't contain any country/region code
so I get a neutral culture that doesn't have any DataTimeFormatInfo

Is there a way to get the prefered date and time settings for the user that
requested the page?

/claes
May 19 '06 #1
4 1989
Hi,

Thank you for posting!

ASP.NET 2.0 has a new feature called 'Auto-Culture Handling': it maps
Accept-Language headers to CultureInfo objects and attaches them to the
current thread. Auto-Culture handling can be enabled for individual pages
by including 'Culture="auto" UICulture="auto"' attributes in the @ Page
directive. It can be enabled site-wide by including a <globalization
culture="auto" uiCulture="auto"/> element in web.config.

Since DataTime's format functions such as ToShortDateString() automatically
uses formatting information derived from the current culture, so for your
requirement, I think simply call these functions without specifying a
DateTimeFormatInfo would be suffice.

If there's anything unclear, please feel free to post here.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

May 22 '06 #2
Ok, sounds cool. I'll try that
Any way to get hold of this "auto-culture" from code? I would like to get
some info from the corresponding DateTimeFormatInfo, such as the
FirstDayOfWeek property and DayNames collection

/claes
"Walter Wang [MSFT]" <wa****@online.microsoft.com> wrote in message
news:8R**************@TK2MSFTNGXA01.phx.gbl...
Hi,

Thank you for posting!

ASP.NET 2.0 has a new feature called 'Auto-Culture Handling': it maps
Accept-Language headers to CultureInfo objects and attaches them to the
current thread. Auto-Culture handling can be enabled for individual pages
by including 'Culture="auto" UICulture="auto"' attributes in the @ Page
directive. It can be enabled site-wide by including a <globalization
culture="auto" uiCulture="auto"/> element in web.config.

Since DataTime's format functions such as ToShortDateString()
automatically
uses formatting information derived from the current culture, so for your
requirement, I think simply call these functions without specifying a
DateTimeFormatInfo would be suffice.

If there's anything unclear, please feel free to post here.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

May 22 '06 #3
Never mind. I see that I actually get the localized DateTimeFormatInfo using
DateTimeFormatInfo.Current
Thank you. Works perfect now

/claes

"Claes Bergefall" <lo*****@nospam.nospam> wrote in message
news:OR**************@TK2MSFTNGP02.phx.gbl...
Ok, sounds cool. I'll try that
Any way to get hold of this "auto-culture" from code? I would like to get
some info from the corresponding DateTimeFormatInfo, such as the
FirstDayOfWeek property and DayNames collection

/claes
"Walter Wang [MSFT]" <wa****@online.microsoft.com> wrote in message
news:8R**************@TK2MSFTNGXA01.phx.gbl...
Hi,

Thank you for posting!

ASP.NET 2.0 has a new feature called 'Auto-Culture Handling': it maps
Accept-Language headers to CultureInfo objects and attaches them to the
current thread. Auto-Culture handling can be enabled for individual pages
by including 'Culture="auto" UICulture="auto"' attributes in the @ Page
directive. It can be enabled site-wide by including a <globalization
culture="auto" uiCulture="auto"/> element in web.config.

Since DataTime's format functions such as ToShortDateString()
automatically
uses formatting information derived from the current culture, so for your
requirement, I think simply call these functions without specifying a
DateTimeFormatInfo would be suffice.

If there's anything unclear, please feel free to post here.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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


May 22 '06 #4
You are welcome.

Have a nice day!

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

May 23 '06 #5

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

Similar topics

60
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm ...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
0
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
1
by: Carlettus | last post by:
Dear All, sorry but I'm not sure if this is the right place to post my problem. I was using the following asp code to create users in Active Directory. Suddenly, and I don't know the reason, users...
0
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.