search
LoginSignup
1
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

updated at

c#で六曜の計算

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;
}

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
1
Help us understand the problem. What are the problem?