Home > Visual C# > Convert Westen datetime to Japanese calendar

Convert Westen datetime to Japanese calendar

using System;
using System.Globalization;

class WarekiSample1 {
   static void Main() {
      DateTime 日付 = new DateTime(2003, 7, 1, 12, 34, 56);
      JapaneseCalendar カレンダー = new JapaneseCalendar();
      Console.WriteLine(カレンダー.GetEra(日付));
      // 出力:4
      string [] 元号名 = { "明治", "大正", "昭和", "平成" };
      Console.WriteLine(元号名[カレンダー.GetEra(日付) - 1]);
      // 出力:平成
      Console.WriteLine(カレンダー.GetYear(日付));
      // 出力:15
   }
}
Advertisements
Categories: Visual C# Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: