信息发布→ 登录 注册 退出

自定义时间格式转换代码分享

发布时间:2026-01-11

点击量:

复制代码 代码如下:
/// <summary>
        /// 将日期字符串转换为日期类型
        /// </summary>
        /// <param name="strDateTime">形如"2012年5月14日"的日期字符串</param>
        private DateTime ParseDateTime(string strDateTime)
        {
            ////Like: string strDateTime = "2012年5月14日";
            DateTime dateTime;
            if (DateTime.TryParseExact(strDateTime, "yyyy年M月d日", new System.Globalization.CultureInfo("en-US"), System.Globalization.DateTimeStyles.AssumeLocal, out dateTime))
            {
                return dateTime;
            }
            else
            {
                return DateTime.Today;
            }
        }

标签:# nbsp  # Globalization  # AssumeLocal  # return  # Today  # CultureInfo  # en  # DateTimeStyles  # DateTime  # gt  # 时间格式转换  # span  # BR  # lt  # summary  # private  # param  # strDateTime  # 形如  # 转换为  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!