HowTo : C# change DateTime format programmatically

by toy

When you use Datetime. Now in c#, it’ll give u a datetime as same as in your computer configured. If you want to change it by programmatically. use the following code.

1
2
3
4
5
6
7
using System.Globalization;

private DateTime dt = DateTime.Now;
private DateTimeFormatInfo  dfi = new DateTimeFormatInfo();
private CultureInfo ci = new CultureInfo("th-TH"); // Change where is you culture do you want

Console.WriteLine(dt.ToString("d",ci));

Reference : http://msdn2.microsoft.com/en-us/library/az4se3k1(VS.71).aspx