Thai year from 2558 to 2015

How to convert the Buddhist date and time format to the Gregorian format (for example, for Thailand 2558 → 2015)?

using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ThailandBuddhistCalendarTest
{
    class Program
    {
        private const string DateFormat = "yyyy-MM-dd";
        private const string DateTimeOffsetFormat = "yyyy-MM-dd'T'HH:mm:sszzz";

        static void Main(string[] args)
        {
            var ci = new CultureInfo("th-TH");
            var today = DateTime.Now.ToString(DateFormat, ci); // today == "2558-05-22"
        }
    }
}
+6
source share
4 answers

DateTime.NowGenerates your local time using GregorianCalenderthe default. If you want to create this time in ThaiBuddhistCalendar, you can get it with an instance of this calendar object.

Now you can use these values ​​in DateTime(Int32, Int32, Int32, Int32, Int32, Int32) constructorto create DateTime.

After that, you can format DateTimein a specific format.

var now = DateTime.Now;
int thaiYear = new ThaiBuddhistCalendar().GetYear(now);
int thaiMonth = new ThaiBuddhistCalendar().GetMonth(now);
int thaiDay = new ThaiBuddhistCalendar().GetDayOfMonth(now);
int thaiHour = new ThaiBuddhistCalendar().GetHour(now);
int thaiMinute = new ThaiBuddhistCalendar().GetMinute(now);
int thaiSecond = new ThaiBuddhistCalendar().GetSecond(now);

var thaiDateTime = new DateTime(thaiYear, thaiMonth, thaiDay, thaiHour, thaiMinute, thaiSecond);
Console.WriteLine(thaiDateTime.ToString("yyyy-MM-dd"));

The result will be:

2558-05-22

From http://www.thaiworldview.com/feast/feast.htm

543 . 2015 - 2558 .

, Calender, , InvariantCulture.

var today = DateTime.Now.ToString(DateFormat, CultureInfo.InvariantCulture)); // 2015-05-22
+1

ThaiBuddhistCalendar.

, , :

ThaiBuddhistCalendar cal = new ThaiBuddhistCalendar();
cal.ToDateTime(2558, 2, 1, 0, 0, 0, 0);
.ToString("yyyy-MM-dd") // returns 2015-01-01

DateTime, :

ThaiBuddhistCalendar cal = new ThaiBuddhistCalendar();
DateTime now = DateTime.Now;
DateTime thai = new DateTime(cal.GetYear(now), cal.GetMonth(now), now.Day);
+1

: Culture, GregorianCalendar , Soner Gönül .

DateTime , Year 2558 2015.

DateTime , gregorian calendar. :

buddhistCalendar.ToDateTime(2558,5,22,0,0,0,0) != new DateTime(2558,5,22,0,0,0,0)

buddhistCalendar.ToDateTime(2558,5,22,0,0,0,0) == new DateTime(2015,5,22,0,0,0,0)

If you want to get the year or any other value set DateTimefor a specific calendar, use the appropriate form of the method, in the calendar, like calendar.GetYear(dateTime).

Otherwise you will receive

new DateTime(2558,5,22,0,0,0,0).Year == 2558

and

buddhistCalendar.GetYear(new DateTime(2558,5,22,0,0,0,0)) == 3101
+1
source

I suggest an easy way to solve your problem.

//First, Get your date in long type because we must use long in the next step.
//Or if you have your time in string type just use
//long yourDateTicks = Convert.ToDateTime(yourStringDate).Ticks;

long yourDateTicks = DateTime.Now.Ticks;

//split your DateTime into Day, Month, Year.

int day = new DateTime(yourDateTicks).Day;
int month = new DateTime(yourDateTicks).Month;
int year = new DateTime(yourDateTicks).Year;

//Did you see the type of them above? Of course, It Integer.
//So you can convert your year into B.C. by simply -543

int bcYear = year - 543;

//Finally, put your items into the blog again and format your desire.

DateTime bcDate = new DateTime(bcYear, month, day);
String bcDateFormat = bcDate.ToString("yyyy-MM-dd");

Attention: if your local time is not in Thailand, your year will be BC. - 543 years old. Try the violin

0
source

Source: https://habr.com/ru/post/1589400/


All Articles