September 2009
M T W T F S S
« Aug   Oct »
 123456
78910111213
14151617181920
21222324252627
282930  

Convert DateTime Thai – Eng culture (Buddha – Christ Ex. year 2009 is 2552)

public static  DateTime DateTimeCulture()
    {
        //=========================================================
        //======== convert year: crist to buddha ==================
        int _day, _month, _year;
        DateTime _date;
        DateTime _dateRerurn;
        string strThaiDate; string strEndDate;

        _day = 2; _month = 12; _year = 2005;

        strEndDate = _day.ToString("00") + _month.ToString("00") + _year.ToString("0000");
        DateTime.TryParseExact(strEndDate, "MM/dd/yyyy", new CultureInfo("en-US"), DateTimeStyles.None, out _date);

        ThaiBuddhistCalendar b = new ThaiBuddhistCalendar();
        int thaiYear = b.GetYear(_date); //(return year string buddha)<----

        //=========================================================
        //======== convert year: buddha to crist ==================
        _day = b.GetDayOfMonth(_date);
        _month = b.GetMonth(_date);
        _year = b.GetYear(_date);

        //_dateRerurn = b.ToDateTime(_year, _month, _day, 0, 0, 0, 0, ThaiBuddhistCalendar.ThaiBuddhistEra);
        strThaiDate = _day.ToString("00") + "/" + _month.ToString("00") + "/" + _year.ToString("0000");
        DateTime.TryParseExact(strThaiDate, "dd/MM/yyyy", new CultureInfo("th-TH"), DateTimeStyles.None, out _dateRerurn);

        return _dateRerurn;
    }
ref: http://www1.cs.columbia.edu/~lok/csharp/refdocs/System.Globalization/types/DateTimeFormatInfo.html
ref: http://greatfriends.biz/webboards/msg.asp?id=8960

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>