查API 
public class SimpleDateFormat
extends DateFormat
SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting. However, you are encouraged to create a date-time formatter with either getTimeInstance, getDateInstance, or getDateTimeInstance in DateFormat. Each of these class methods can return a date/time formatter initialized with a default format pattern. You may modify the format pattern using the applyPattern methods as desired. For more information on using these methods, see DateFormat. Date and Time Patterns
Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, unquoted letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (') to avoid interpretation. "''" represents a single quote. All other characters are not interpreted; they're simply copied into the output string during formatting or matched against the input string during parsing. The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved): 

解决方案 »

  1.   

    DateFormat是一个简单工厂模式,,
    用起来很简单的,,你试一试就会了
      

  2.   

    public boolean isDate(String chString){

    if(chString.indexOf("-") <= 0){
    return false;
    }
    SimpleDateFormat dateFormatter = new SimpleDateFormat( "yyyy-MM-dd" );
    try{
    //将字符串类型转化为时间类型( "yyyy-MM-dd" )  
    Date tempTime =dateFormatter.parse(chString);
    return true;

    }
    catch(Exception e){
    System.out.println(e.getMessage());
    return false;
    }

    }
    来验证输入的字符串是否是符合条件的时间类型是为什么不能判断2004-45-45类似的字符串是非法的,请问有什么别的解决方案或此方法的改进??
    谢谢!
      

  3.   

    以后,问这样的问题之前先查查api,那里都有的,要学会自己研究,不要老问别人
      

  4.   

    RE:gsen(进入就是上帝) 
    那你认为我变的程序还需要什么改进吗?
    我现在已经用别的方法实现了,但是我觉得这个方法比我现在编的那个要好!