zoukankan      html  css  js  c++  java
  • 日期格式限定

        /// <summary>
            
    /// 日期かどうか、判断する
            
    /// </summary>
            
    /// <returns>True:日期だ、False:日期ではない</returns>
            #region "入力時間フォーマットチャック"
            
    private bool checkDate(string getDate)
            {
                
    //日期フォーマットを設置する

                
    string ruler = @"^[0-9]{4}[/]{1}[0-9]{2}[/][0-9]{2}$";

                
    //対象月の『yyyy/MM』形を検査する
                if (getDate.Length > 7 && getDate.Length < 11 && Regex.IsMatch(getDate,ruler) == true)
                {
                    
    //1900年より小さいの日期を判断
                    if (Convert.ToInt32(getDate.Substring(0,4)) < 1900)
                    {
                        
    return false;
                    }
                    
    //月を限制
                    if (Convert.ToInt32(getDate.Substring(5,2)) == 0 || Convert.ToInt32(getDate.Substring(5,2)) >12)
                    {
                        
    return false;
                    }
                    
    //日期フォーマットを限制:2009/03/00||2009/03/55だめ
                    try
                    {
                        Convert.ToDateTime(getDate);
                    }
                    
    catch (Exception)
                    {
                        
    return false;
                        
                    }
                    
    return true;
                    
                }
                
    else
                {
                    
    return false;
                }
                
            }
            
    #endregion
  • 相关阅读:
    pytest实际编码中特殊问题的解决
    python+locust性能测试实例
    python使用eval动态调用函数及其在测试用例中断言的应用
    python中列表生成式的两种用法
    pycharm中的Terminal无法使用git命令
    ruamel.yaml的使用
    pip安装模块失败如何解决
    locust的setup等相关函数的使用
    python模块-optparse(解析命令行参数)
    (转)locust源码目录结构及模块作用
  • 原文地址:https://www.cnblogs.com/wequst/p/1408473.html
Copyright © 2011-2022 走看看