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
  • 相关阅读:
    idea新建web项目
    wampserver的MySQL和本机MySQL冲突导致空密码登录报错
    while-else if
    格式化输出
    Zookeeper
    仿真手写Spring核心原理v1.0
    各设计模式总结与对比
    装饰者模式和观察者模式
    模板模式和适配器模式
    委派模式和策略模式
  • 原文地址:https://www.cnblogs.com/wequst/p/1408473.html
Copyright © 2011-2022 走看看