Ejemplo n.º 1
0
        /// <summary>
        /// 验证输入字符串是否为日期和时间
        /// </summary>
        /// <param name="obj">输入的字符串</param>
        /// <param name="delimiter">分隔符</param>
        /// <returns>
        /// true是日期和时间
        /// false不是日期和时间
        /// </returns>
        public static bool IsDateTime(this string obj, string delimiter = "-/.")
        {
            if (!obj.VerifyRegex(RegexData.DateTime(delimiter), true))
            {
                return(false);
            }
            int index = obj.IndexOf(' ');

            if (index < 0)
            {
                index = obj.IndexOf('T');
            }
            if (index < 0)
            {
                return(false);
            }
            string dataStr = obj.Substring(0, index);

            return(dataStr.IsDate(delimiter));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 验证输入字符串是否为日期
        /// </summary>
        /// <param name="obj">输入的字符串</param>
        /// <param name="delimiter">分隔符</param>
        /// <returns>
        /// true是日期
        /// false不是日期
        /// </returns>
        public static bool IsDate(this string obj, string delimiter = "-/.")
        {
            if (!obj.VerifyRegex(RegexData.Date(delimiter), true))
            {
                return(false);
            }
            var resM = false;

            char[] delimiters = delimiter.ToCharArray();
            foreach (char item in delimiters)
            {
                string[] dateStr = obj.Split(item);
                if (dateStr.Length != 3)
                {
                    continue;
                }
                int month = int.Parse(dateStr[1]);
                if (month == 2)
                {
                    int year = int.Parse(dateStr[0]);
                    int day  = int.Parse(dateStr[2]);
                    if (year % 4 == 0)
                    {
                        resM = true;
                    }
                    else
                    {
                        if (day <= 28)
                        {
                            resM = true;
                        }
                    }
                }
                else
                {
                    resM = true;
                }
                break;
            }
            return(resM);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 获取输入字符串中所有的日期和时间
 /// </summary>
 /// <param name="obj">输入的字符串</param>
 /// <param name="delimiter">分隔符</param>
 /// <returns>
 /// 字符串中所有的日期和时间
 /// </returns>
 public static MatchCollection GetDateTime(this string obj, string delimiter = "-/.")
 {
     return(obj.GetVerifyRegex(RegexData.DateTime(delimiter), false));
 }