Datagrid Column Date Format : Recognizes Browser Culture

R

Rod Billett

There have been many posts related to displaying a Formatted Date, but none
referenced how to adapt to the Browsers Culture. I tried using the {0:d} as
others have posted, but this reverts to the current Threads ShortDateFromat
and not the browsers format.

To format a Date Column within a datagrid to the browsers culture (
Tools>Internet Options> Languages...)
do the following on your column

System.Globalization.CultureInfo ciO =
System.Globalization.CultureInfo.CreateSpecificCulture(this.Context.Request.
UserLanguages[0]);
DateColumn.DataFormatString = "{0:" + ciO.DateTimeFormat.ShortDatePattern +
"}";

Given a date of May 24th, 2003 the date column will be formatted as follows

US = 5/24/2003
French = 24/5/2003

Hope this Helps someone out...
Rod
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top