通过字符串获得DateTime?

2017-01-25 17:22:47  访问(1376) 赞(0) 踩(0)


        /// <summary>
        /// 通过字符串获得DateTime?
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public DateTime? GetDateTimeNullByStr(string str, DateTime? defaultValue)
        {
            if (str == null || str.Length == 0)
                return null;

            DateTime theResult = DateTime.MinValue;

            if (DateTime.TryParse(str, out theResult))
                return theResult;

            return defaultValue;
        }


标签:通过字符串获得DateTime? 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)