查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):
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):
解决方案 »
- jsp开发容器的问题
- 从mysql中读不出数据
- applet与socket通信问题请教高手
- 高手看过来,INNERHTML 有没有逆运算啊,具体怎么做
- 浏览需要JAVA的网站,提示“Please use a Java enabled browser”
- 关于if else 在jsp中的使用问题
- 那种页面扩展名是 .do的网站应用的是java的什么技术?
- 请教怎么在Windows Server 2003上安装ServletExec
- 俺头一次做点东西,各位大虾帮忙指点指点了
- 赠送高分!!!在jsp中怎么使用Content-disposition !
- 关于初始化数据库的问题!!
- 一起来翻译一下介绍jsp技术的一句英语
用起来很简单的,,你试一试就会了
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类似的字符串是非法的,请问有什么别的解决方案或此方法的改进??
谢谢!
那你认为我变的程序还需要什么改进吗?
我现在已经用别的方法实现了,但是我觉得这个方法比我现在编的那个要好!