轉民國日期 & 民國轉西元

摘要:轉民國日期 & 民國轉西元

using System.Globalization;   
//民國日期
                CultureInfo m_ciTaiwan = new CultureInfo("zh-TW");
                m_ciTaiwan.DateTimeFormat.Calendar = m_ciTaiwan.OptionalCalendars[2];
                string strDate = DateTime.Now.Date.ToString("yyyyMMdd", m_ciTaiwan);

/// <summary>
    /// 民國轉西元
    /// </summary>
    /// <param name="TwDate"></param>
    /// <returns></returns>
    public string ChangCalender(string TwDate)
    {
        string NewDate = string.Empty;
        int b;
        if (!int.TryParse(TwDate, out b))
        {
            //日期格式轉換錯誤!
            return NewDate;
        }
         
        int vYear = b/10000;
        int vMonth = (b % 10000)/100;
        int vDay = (b % 100);
        DateTime vDate = DateTime.Parse(string.Format("{0}/{1}/{2} 00:00:00", vYear + 1911, vMonth, vDay));
        NewDate = vDate.ToString("yyyyMMdd");
        return NewDate;
    }