2009/03/30

[C# 2.0] How to load different culture's date time?

How to load other culture's Date and Time format without changing the Region's setting in the Control Panel? Here is what I did:
//change the culture in order to read the DateTime
DateTimeFormatInfo oDateTimeFormatInfo = (new CultureInfo("zh-tw")).DateTimeFormat;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("zh-tw");
Don't forget to include the namespace:

using System.Globalization;
using System.Threading;

Reference

2 comments:

  1. i tried your code but nothing happened do i make some mistake when using it ?
    honestly i didn't understand what your code should do, can u explain me some ?

    Thanks...

    ReplyDelete
  2. Hi Ahmet,

    If you want to read other culture's DateTime, you can take a look at this link: http://tinyurl.com/ybg3nou

    Here is a good example: http://tinyurl.com/yap8r32

    Let me know if you still have problems.

    ReplyDelete