/// <summary>
        /// 将object值转换成DateTime类型,失败则返回DateTime.MinValue
        /// </summary>
        /// <param name="value">转换对象</param>
        /// <param name="defautValue">默认值</param>
        /// <param name="dtFormate">日期显示格式</param>
        /// <returns></returns>
        public static DateTime ToDateTime(object value, DateTime defautValue, DTFormate dtFormate)
        {
            DateTime dm = ToDateTime(value, defautValue);

            dm = ToDateTime(DateTimeToString(dm, dtFormate));
            return(dm);
        }
Example #2
0
        public static String DateTimeToString(Object value, DTFormate dtFormate)
        {
            if (value == null)
            {
                return(String.Empty);
            }

            DateTime m_dt = (DateTime)value;

            switch (dtFormate)
            {
            case DTFormate.SHORT_EN_US: return(m_dt.ToString("yyyy-MM-dd"));

            case DTFormate.SHORT_ZH_CN: return(m_dt.ToString("yyyy年MM月dd日"));

            case DTFormate.LONG_EN_US: return(m_dt.ToString("yyyy-MM-dd hh:mm:ss"));

            case DTFormate.LONG_ZH_CN: return(m_dt.ToString("yyyy年MM月dd日hh时mm分ss秒"));

            default: return(m_dt.ToString("yyyy-MM-dd"));
            }
        }
        /// <summary>
        /// 将DateTime转换成字符串,失败则返回空
        /// </summary>
        /// <param name="value">转换对象</param>
        /// <param name="dtFormate">日期显示格式</param>
        /// <returns></returns>
        public static String DateTimeToString(object value, DTFormate dtFormate)
        {
            DateTime dm = ToDateTime(value);

            return(DateTimeToString(dm, dtFormate));
        }