欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-02-18 23:36:46
复制代码 代码如下:///         /// 将日期字符串转换为日...

复制代码 代码如下:

/// <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;
            }
        }