using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace ChuPiao.Common.Utils
{
    /// <summary>
    /// Convert.的工具类
    /// </summary>
    public class ConvertUtil
    {
        /// <summary>
        /// 2013-08-21 09:09:13,264 [14] INFO  jz [(null)] - 解包组包异常：该字符串未被识别为有效的 DateTime。
        /// </summary>
        /// <param name="datetimestr"></param>
        /// <returns></returns>
        public static DateTime StrToDateTime(string datetimestr)
        {
            try
            {
                CultureInfo CultureInfo = new CultureInfo("en-US");
                CultureInfo.DateTimeFormat.TimeSeparator = ":";
                CultureInfo.DateTimeFormat.DateSeparator = "-";
                CultureInfo.DateTimeFormat.LongDatePattern = "yyyy-MM-dd";
                CultureInfo.DateTimeFormat.LongTimePattern = "HH:mm:ss";
                return DateTime.Parse(datetimestr, CultureInfo.DateTimeFormat);
            }
            catch (Exception ex)
            {
                Logger.Log.Info("字符串[" + datetimestr + "]转换成DateTime错误：" + ex.ToString());
                throw ex;
            }
        }

        public static DateTime StrToDateTime(object datetimestr)
        {
            return StrToDateTime(datetimestr.ToString());
        }
    }
}
