直接放乾貨
/// <summary>
/// 是否為民國日期
/// </summary>
/// <param name="dateStr"></param>
/// <returns></returns>
public static bool IsTwDate(this string dateStr)
{
CultureInfo tc = new CultureInfo("zh-TW");
tc.DateTimeFormat.Calendar = new TaiwanCalendar();
DateTime result;
if (DateTime.TryParseExact(dateStr, "d", tc, DateTimeStyles.None, out result))
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 西元轉民國年
/// </summary>
/// <param name="datetime"></param>
/// <returns></returns>
public static string ToTaiwanDate(this DateTime datetime)
{
TaiwanCalendar taiwanCalendar = new TaiwanCalendar();
return string.Format("{0}/{1}/{2}",
taiwanCalendar.GetYear(datetime),
datetime.Month,
datetime.Day);
}