zoukankan      html  css  js  c++  java
  • 西暦=>和暦、和暦=>西暦

    #region 西暦=>和暦、和暦=>西暦
            /// <summary>
            /// 西暦=>和暦
            /// </summary>
            /// <param name="strDate">西暦日期</param>
            /// <param name="strWarekiFormat">例:ggyy年DD月dd日</param>
            /// <returns>例:平成23年08月03日 </returns>
            public string ConvertDateToWareki01(string strDate, string strWarekiFormat)
            {
                 string strWareki = "";
                 try
                 {
                     CultureInfo ci = new CultureInfo("ja-JP", true);
                     Calendar cal = new JapaneseCalendar();
                     ci.DateTimeFormat.Calendar = cal;
                     DateTime vCurrentDate = DateTime.Parse(strDate);

                     strWareki = vCurrentDate.ToString(strWarekiFormat, ci.DateTimeFormat);
                 }
                 catch
                 {
                 }
                return strWareki;
            }
            /// <summary>
            /// 西暦=>和暦
            /// </summary>
            /// <param name="strDate">西暦日期</param>
            /// <param name="strWarekiFormat">例:yy年DD月dd日</param>
            /// <returns>例:平23年08月03日</returns>
            public string ConvertDateToWareki02(string strDate, string strWarekiFormat)
            {
                string strWareki = "";
                try
                {
                    CultureInfo ci = new CultureInfo("ja-JP", true);
                    Calendar cal = new JapaneseCalendar();
                    ci.DateTimeFormat.Calendar = cal;
                    DateTime dt = DateTime.Parse(strDate);

                    strWareki = ci.DateTimeFormat.GetAbbreviatedEraName(cal.GetEra(dt)) + dt.ToString(strWarekiFormat, ci);
                }
                catch
                {
                }
                return strWareki;
            }
            /// <summary>
            /// 西暦=>和暦
            /// </summary>
            /// <param name="strDate">西暦日期</param>
            /// <param name="strWarekiFormat">例:yy年DD月dd日</param>
            /// <returns>例:H23年08月03日</returns>
            public string ConvertDateToWareki03(string strDate, string strWarekiFormat)
            {
                string strWareki = "";
                try
                {
                    string[] engEras = { "M", "T", "S", "H" };
                    CultureInfo ci = new CultureInfo("ja-JP", true);
                    Calendar cal = new JapaneseCalendar();
                    ci.DateTimeFormat.Calendar = cal;
                    DateTime dt = DateTime.Parse(strDate);

                    strWareki = engEras[cal.GetEra(dt) - 1] + dt.ToString(strWarekiFormat, ci);
                }
                catch
                {
                }
                return strWareki;
            }
            /// <summary>
            /// 西暦=>和暦
            /// </summary>
            /// <param name="strDate">西暦日期</param>
            /// <param name="strWarekiFormat">例:yy年DD月dd日</param>
            /// <returns>例:H23年08月03日</returns>
            public string ConvertDateToWareki04(string strDate, string strWarekiFormat)
            {
                string strWareki = "";
                try
                {
                    CultureInfo ci = new CultureInfo("ja-JP", true);
                    Calendar cal = new JapaneseCalendar();
                    ci.DateTimeFormat.Calendar = cal;
                    DateTime dt = DateTime.Parse(strDate);

                    Type t = typeof(DateTimeFormatInfo);
                    PropertyInfo pi = t.GetProperty("AbbreviatedEnglishEraNames", BindingFlags.NonPublic | BindingFlags.Instance);
                    string[] engEras = (string[])pi.GetValue(ci.DateTimeFormat, null);

                    strWareki = engEras[cal.GetEra(dt) - 1] + dt.ToString(strWarekiFormat, ci);
                }
                catch
                {
                }
                return strWareki;
            }
            /// <summary>
            /// 和暦=>西暦
            /// </summary>
            /// <param name="strWareki">和暦日期(例:平成23年08月03日、平23年08月03日、H23年08月03日)</param>
            /// <param name="strWarekiFormat">和暦日期と対応フォマット(例:yy年MM月dd日)</param>
            /// <param name="iStartIndex">元号の次位置</param>
            /// <param name="strDateFormat">例:yyyy/MM/dd</param>
            /// <returns>例:2011/08/03</returns>
            public string ConvertWarekiToDate(string strWareki, string strWarekiFormat, string strDateFormat,int iStartIndex)
            {
                string strDate = "";
                try
                {
                    CultureInfo ci = new CultureInfo("ja-JP", true);
                    Calendar cal = new JapaneseCalendar();
                    ci.DateTimeFormat.Calendar = cal;
                    strDate = DateTime.ParseExact(strWareki.Substring(iStartIndex, strWareki.Length - iStartIndex), strWarekiFormat, ci).ToString(strDateFormat);
                }
                catch
                {
                }
                return strDate;
            }
            #endregion

  • 相关阅读:
    CentOS安装node.js-8.11.1+替换淘宝NPM镜像
    【推荐】CentOS安装gcc-4.9.4+更新环境+更新动态库
    申请安装阿里云免费SSL证书
    服务器安全加固
    【推荐】优秀代码
    CenOS登录失败处理功能
    Ubuntu修改密码及密码复杂度策略设置
    mysql 5.7添加server_audit 安全审计功能
    快速安装jumpserver开源堡垒机
    oracle 11g 配置口令复杂度
  • 原文地址:https://www.cnblogs.com/secying/p/2125930.html
Copyright © 2011-2022 走看看