C#(ASP.NET)西暦の旧暦の簡単な方法

2751 ワード

Dot Netプラットフォームは、グローバル化へのサポートが非常によく、称賛せざるを得ません.
通常、西暦を旧暦に変えるのは煩わしいことで、閏年や閏月などの対照表を整理する必要があります.
はい.Netプラットフォームでは、国際化のサポートがあり、これらのものは、すでに提供されています.私たちがしなければならないのは、利用するだけです.
あまり話さないで、直接コードをつけます.
 
/// <summary>

///          

/// </summary>

/// <remarks>  :    DeltaCat</remarks>

/// <example>  :http://www.zu14.cn</example>

/// <param name="solarDateTime">    </param>

/// <returns>     </returns>

static string SolarToChineseLunisolarDate(DateTime solarDateTime)

{

    System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();



    int year = cal.GetYear(solarDateTime);

    int month = cal.GetMonth(solarDateTime);

    int day = cal.GetDayOfMonth(solarDateTime);

    int leapMonth = cal.GetLeapMonth(year);

    return string.Format("  {0}{1}({2}) {3}{4} {5}{6}"

                        , "          "[(year - 4) % 10]

                        , "            "[(year - 4) % 12]

                        , "            "[(year - 4) % 12]

                        , month == leapMonth ? " " : ""

                        , "             "[leapMonth > 0 && leapMonth <= month ? month - 1 : month]

                        , "    "[day / 10]

                        , "          "[day % 10]

                        );

}

 
使用方法は非常に簡単です.
string旧暦=SolarToChineseLunisolarDate(DateTime.Today);
[全文を読む]