查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):
解决方案 »
- Struts2 头痛的页面跳转问题
- jsp关于form表单为两个按钮设置不同action的问题
- 手机认证问题。
- ant和junit
- 请教一个问题,查询1000万数据,然后把它写入csv文件。
- 奇怪:为什么取当前时间Util.getFormatDate("yyyy-MM-dd HH:mm")取出来的是格林威治时间?请问如何取出当前北京时间。
- 本人求关于城市信息港的源码! 有的朋友请和我联系QQ:249841933 谢谢!
- 菜鸟发问:如何把comcat的默认主页换成我自己做的页面?
- 下一步我该怎么办?
- 哪儿有jsp的安装( windows 2000 server 简体中文版)?
- 关于初始化数据库的问题!!
- 一起来翻译一下介绍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类似的字符串是非法的,请问有什么别的解决方案或此方法的改进??
谢谢!
那你认为我变的程序还需要什么改进吗?
我现在已经用别的方法实现了,但是我觉得这个方法比我现在编的那个要好!