Showing posts with label date format. Show all posts
Showing posts with label date format. Show all posts

Wednesday, October 6, 2010

Set DateFormat

We can set current application's date style using this in C++/CLI

System::Threading::Thread^ pThread;
System::Globalization::CultureInfo^ pCultureInfo;
pThread = System::Threading::Thread::CurrentThread;
pCultureInfo = (System::Globalization::CultureInfo^)pThread->CurrentCulture->Clone();
pCultureInfo->DateTimeFormat->ShortDatePattern = "dd.MM.yyyy";
pThread->CurrentCulture = pCultureInfo;

In WPF application, the same thing is doing
like

CultureInfo culutreInfo = System.Threading.Thread.CurrentThread.CurrentCulture.Clone() as CultureInfo;
culutreInfo.DateTimeFormat.ShortDatePattern = "MMM dd/yyyy";
System.Threading.Thread.CurrentThread.CurrentCulture = culutreInfo;

or

Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";

Also we can set a particular datepicker's date format like this,

CultureInfo cultureInfo = new CultureInfo("en-US");
DateTimeFormatInfo dateInfo = new DateTimeFormatInfo();
dateInfo.ShortDatePattern = "MM/yyyy";
cultureInfo.DateTimeFormat = dateInfo;
radDatePicker1.Culture = cultureInfo;


or

CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
culture.DateTimeFormat.ShortDatePattern = "MMM/dd/yyyy";
datePicker1.Culture = culture;