LoginSignup
0
1

More than 3 years have passed since last update.

c#で六曜の計算

Last updated at Posted at 2019-12-22

JapaneseLunisolarCalendarを使って計算すると便利です

static int RokuyoDate(DateTime clacDay)
{
    JapaneseLunisolarCalendar jpnOldDays = new JapaneseLunisolarCalendar();
    int oldMonth = jpnOldDays.GetMonth(clacDay); //旧暦の月を取得
    int oldDay   = jpnOldDays.GetDayOfMonth(clacDay);//旧暦の日を取得 

    var aaa = jpnOldDays.GetYear(clacDay);
    var bbb = jpnOldDays.GetEra(clacDay);

    //閏月を取得
    int uruMonth = jpnOldDays.GetLeapMonth(
            jpnOldDays.GetYear(clacDay),
            jpnOldDays.GetEra(clacDay));

    //閏月含む場合の月を補正
    if ((uruMonth > 0) && (oldMonth - uruMonth >= 0))
    {
        oldMonth = oldMonth - 1;              //旧暦月の補正
    }

    //ルールとしては
    // (月 + 日) % 6 の結果が六曜になり
    //大安→赤口→先勝→友引→先負→仏滅
    int rokuyo = (oldMonth + oldDay) % 6;
    return rokuyo;
}
0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1