DateTimeFormatInfo dtfi = new CultureInfo(CultureInfo.CurrentCulture.Name).DateTimeFormat; string eraName = dtfi.GetEraName(dtfi.Calendar.GetEra(DateTime.Now)); Console.WriteLine(eraName);
DateTimeFormatInfo dtfi = new CultureInfo("ja-JP").DateTimeFormat; JapaneseCalendar calendar = new JapaneseCalendar(); string eraName = dtfi.GetEraName(calendar.GetEra(new DateTime(2021, 10, 1, calendar))); Console.WriteLine(eraName);This code sets the culture to ja-JP (Japanese) and creates a new instance of the JapaneseCalendar. It then uses the DateTimeFormatInfo object to get the name of the era for October 1st, 2021 (which is the first day of the Reiwa era in Japan). Overall, the GetEraName method is useful for retrieving the name of an era in a specific calendar, which can be important when working with dates and times in different cultures.