区分24小时和12小时的时间格式转换为

   #region 时间格式转换为yyyy-mm-dd hh:mm:ss.fff
        /// <summary>
        /// 时间格式转换为yyyy-mm-dd hh:mm:ss.fff
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string ConvertDateTime(object obj)
        {
            if (obj != null && !string.IsNullOrEmpty(obj.ToString()))
            {
                try
                {
                    return ((System.DateTime)(obj)).ToString("yyyy-MM-dd HH:mm:ss.fff");
                }
                catch
                {
                    return string.Empty;
                }
            }
            return string.Empty;
        }
        #endregion

        #region 时间格式转换为yyyy-mm-dd hh:mm:ss.fff
        /// <summary>
        /// 时间格式转换为yyyy-mm-dd
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string ConvertShortDateTime(object obj)
        {
            if (obj != null && !string.IsNullOrEmpty(obj.ToString()))
            {
                try
                {
                    return ((System.DateTime)(obj)).ToString("yyyy-MM-dd");
                }
                catch
                {
                    return string.Empty;
                }
            }
            return string.Empty;
        }
        #endregion

posted @ 2013-08-12 16:43  永不言败,自信相伴  阅读(546)  评论(0编辑  收藏  举报