示例#1
0
        /// <summary>
        /// Convert from GMT To Date time. '20140421T 071939.000 GMT'
        /// </summary>
        /// <returns></returns>
        public static DateTime ToDateTimeFromGMTFormat(object obj, DateTime defaultValue)
        {
            DateTime returnValue = defaultValue;

            string str = Converrt.ToString(obj);

            int yyyy = 0;
            int MM   = 0;
            int dd   = 0;
            int HH   = 0;
            int min  = 0;
            int ss   = 0;

            if (str.Length > 4)
            {
                yyyy = Converrt.ToInt(str.Substring(0, 4));
            }
            if (str.Length > 6)
            {
                MM = Converrt.ToInt(str.Substring(4, 2));
            }
            if (str.Length > 8)
            {
                dd = Converrt.ToInt(str.Substring(6, 2));
            }

            if (str.Length > 10)
            {
                HH = Converrt.ToInt(str.Substring(9, 2));
            }
            if (str.Length > 11)
            {
                min = Converrt.ToInt(str.Substring(11, 2));
            }
            if (str.Length > 13)
            {
                ss = Converrt.ToInt(str.Substring(13, 2));
            }

            if (yyyy > 0 && MM > 0 && dd > 0)
            {
                returnValue = new DateTime(yyyy, MM, dd, HH, min, ss);
            }

            return(returnValue);
        }
示例#2
0
        /// <summary>
        /// Get the data time variable value from string format.
        /// </summary>
        /// <param name="yyyyMMddHHmm"></param>
        /// <returns></returns>
        public static DateTime GetDateTimeFromString(string yyyyMMddHHmm, DateTime DefaultValue)
        {
            DateTime dt = DateTime.MinValue;
            int      yy = 0, mm = 0, dd = 0, hh = 0, min = 0;

            if (yyyyMMddHHmm.Length >= 4)
            {
                yy = Converrt.ToInt(yyyyMMddHHmm.Substring(0, 4));
            }
            if (yyyyMMddHHmm.Length >= 6)
            {
                mm = Converrt.ToInt(yyyyMMddHHmm.Substring(4, 2));
            }
            if (yyyyMMddHHmm.Length >= 8)
            {
                dd = Converrt.ToInt(yyyyMMddHHmm.Substring(6, 2));
            }
            if (yyyyMMddHHmm.Length >= 10)
            {
                hh = Converrt.ToInt(yyyyMMddHHmm.Substring(8, 2));
            }
            if (yyyyMMddHHmm.Length >= 12)
            {
                min = Converrt.ToInt(yyyyMMddHHmm.Substring(10, 2));
            }

            if (yy == 0 || mm == 0 || dd == 00)
            {
                dt = DefaultValue;
            }
            else
            {
                dt = new DateTime(yy, mm, dd, hh, min, 0);
            }

            return(dt);
        }