Changing date format

G

Gani Pola

Can someone please tell me how I can change the date format (e.g dd/mm/yyyy,
mm/dd/yyyy) in a configuration file?

In my windows app, I can retrieve the windows setting but not my ASP.NET
application.

TIA
GP
 
M

Manoj G [MVP]

Hi,

Do you mean to say you have to pick up the format from the config file and
use that? If that is the case, then you just need to do store your setting
in Web.Config and then use ConfigurationSettings.AppSettings (or GetConfig ,
whichever) and then pass the format to the ToString method of your DateTime
structure instance.
Something like:
myDt.ToString(ConfigurationSettings.AppSettings("DateFormat"))

Be it a windows app or a web app, you can get the current machine's settings
by calling the CultureInfo.InstalledUICulture property. You can extract
Date/time/currency formats from this instance of CultureInfo by using
properties like DateTimeFormat etc..CultureInfo BTW, is in
System.Globalization namespace.

As a better practice, you might consider passing a CultureInfo instance
(implements IFormatProvier) the ToString method or change the current
thread's Culture to display the dates in those corresponding formats, since
date/time formats are culture specific.


--
HTH,
Manoj G [.NET MVP]
http://www15.brinkster.com/manoj4dotnet

PS: Pls avoid cross NG posting as much as possible.
 

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,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top