Changing date format

  • Thread starter Thread starter Gani Pola
  • Start date Start date
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
 
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.
 
Back
Top