public static string ToJaCal(this DateTime d) { JapaneseCalendar jaCal = new JapaneseCalendar(); var nengo = new string[]{ "明治", "大正", "昭和", "平成" }; var nen = nengo[jaCal.GetEra(d) - 1] + jaCal.GetYear(d) + "年"; var tsuki = d.Month + "月"; var hi = d.Day + "日"; return nen + tsuki + hi; }
private void chakkoNenTextBox_Leave(object sender, EventArgs e) { int i; if (int.TryParse(chakkoNenTextBox.Text, out i)) { if (int.Parse(chakkoNenTextBox.Text) > 1868) { JapaneseCalendar jpCalender = new JapaneseCalendar(); //jpCalender.GetEra(DateTime.Parse(chakkoNenTextBox.Text + "-01-01")); string[] Gengo = { "M", "T", "S", "H" }; chakkoNenTextBox.Text = Gengo[jpCalender.GetEra(DateTime.Parse(chakkoNenTextBox.Text + "-12-31")) - 1] + jpCalender.GetYear(DateTime.Parse(chakkoNenTextBox.Text + "-12-31")).ToString(); } else { chakkoNenTextBox.Text = "H" + chakkoNenTextBox.Text; } } }
private string getEraFromWesternYear(string westernYear, string westernMonth, string westernDay) { DateTime date = new DateTime(Convert.ToInt32(westernYear), Convert.ToInt32(westernMonth), Convert.ToInt32(westernDay)); JapaneseCalendar jpCalendar = new JapaneseCalendar(); string[] era = { "明治", "大正", "昭和", "平成" }; return era[jpCalendar.GetEra(date) - 1]; }