示例#1
0
        public static bool TryParse(string dt, out NetTalkDate result)
        {
            bool HasResult = false;

            result = null;
            try
            {
                if (NetTalkIsValid.IsDate(dt))
                {
                    Regex rg = new Regex(NetTalkPatterns.Date);
                    int   y, m, d;
                    Match r = rg.Match(dt);
                    y         = Convert.ToInt32(r.Groups[1].Value);
                    m         = Convert.ToInt32(r.Groups[2].Value);
                    d         = Convert.ToInt32(r.Groups[3].Value);
                    result    = new NetTalkDate(y, m, d);
                    HasResult = true;
                }
                else if (NetTalkIsValid.IsDatetime(dt))
                {
                    Regex rg = new Regex(NetTalkPatterns.DateTime);
                    int   y, m, d, h, min, s;

                    Match r = rg.Match(dt);
                    y         = Convert.ToInt32(r.Groups[1].Value);
                    m         = Convert.ToInt32(r.Groups[2].Value);
                    d         = Convert.ToInt32(r.Groups[3].Value);
                    h         = Convert.ToInt32(r.Groups[4].Value);
                    min       = Convert.ToInt32(r.Groups[5].Value);
                    s         = Convert.ToInt32(r.Groups[6].Value);
                    result    = new NetTalkDate(y, m, d, h, min, s, 0);
                    HasResult = true;
                }
                else if (NetTalkIsValid.IsDateTimeFactor(dt))
                {
                    Regex rg = new Regex(NetTalkPatterns.DateTimeFactor);
                    int   y, m, d, h, min, s;

                    Match r = rg.Match(dt);
                    y         = Convert.ToInt32(r.Groups[1].Value);
                    m         = Convert.ToInt32(r.Groups[2].Value);
                    d         = Convert.ToInt32(r.Groups[3].Value);
                    h         = Convert.ToInt32(r.Groups[4].Value);
                    min       = Convert.ToInt32(r.Groups[5].Value);
                    s         = 0;
                    result    = new NetTalkDate(y, m, d, h, min, s, 0);
                    HasResult = true;
                }
            }
            catch { }

            return(HasResult);
        }
 public static NetTalk.Common.Dates.NetTalkDate PersianDate(this string input)
 {
     NetTalk.Common.Dates.NetTalkDate outpdate = null;
     if (!string.IsNullOrEmpty(input))
     {
         bool result = NetTalk.Common.Dates.NetTalkDate.TryParse(input, out outpdate);
         if (!result)
         {
             outpdate = null;
         }
     }
     else
     {
         outpdate = null;
     }
     return(outpdate);
 }