用DateFormat或SimpleDateFormat来生成Date

解决方案 »

  1.   

    //***************************************************
        //名称:strToDate
        //功能:将指定的字符串转换成日期
        //输入:aStrValue: 要转换的字符串; 
        // aFmtDate: 转换日期的格式, 默认为:"yyyy/MM/dd"
        //      aDteRtn: 转换后的日期
        //输出:
        //返回:TRUE: 是正确的日期格式; FALSE: 是错误的日期格式
        //***************************************************
        public static boolean strToDate(
            String aStrValue,
            String aFmtDate,
            java.util.Date aDteRtn)
        {
            if (aFmtDate.length() == 0)
            {
                aFmtDate = "yyyy/MM/dd";
            }
            SimpleDateFormat fmtDate = new SimpleDateFormat(aFmtDate);
            try
            {
                aDteRtn.setTime(fmtDate.parse(aStrValue).getTime());
            }
            catch (Exception e)
            {
                return (false);
            }        return (true);
        }