实习第一次做项目,虽然用我以前没接触过的JAVA语言,但收获是蛮大的。编程过程中难免出现不懂不会的知识点,以此博客为记,便以一详。测试IDE为Eclipse、IDEA。
1:时间JS控件:my97 DatePicker ---> 97官网
这是一个很方便对时间相关操作的控件,内容很多,详细用法请参考官网,在此只列出我使用的方法(简化后的)。
code
1
<
html
>
2 < head >
3 < script language ="javascript" type ="text/javascript" src ="/scripts/My97DatePicker/WdatePicker.js" ></ script >
4 </ head >
5 < body >
6 < input type ="text" onclick =" WdatePicker()" cssClass="Wdate" />
7 </ body >
8 </ html >
2 < head >
3 < script language ="javascript" type ="text/javascript" src ="/scripts/My97DatePicker/WdatePicker.js" ></ script >
4 </ head >
5 < body >
6 < input type ="text" onclick =" WdatePicker()" cssClass="Wdate" />
7 </ body >
8 </ html >
2: Date
格式化日期输出
code
1
import
java.util.
*
;
2 import java.text.SimpleDateFormat;
3
4 public class test {
5
6 public static void main(String[] args) {
7
8 Date date = new Date();
9 SimpleDateFormat format = new SimpleDateFormat( " yyyy-MM-dd hh:mm:ss " );
10 System.out.println(format.format(date));
11 }
12 }
2 import java.text.SimpleDateFormat;
3
4 public class test {
5
6 public static void main(String[] args) {
7
8 Date date = new Date();
9 SimpleDateFormat format = new SimpleDateFormat( " yyyy-MM-dd hh:mm:ss " );
10 System.out.println(format.format(date));
11 }
12 }
其他操作推荐--->date方法集合
3:判断输入是不是时间格式(正则表达式)
code
private
boolean
judgeFDate()
{
Pattern pattern = Pattern.compile( " \\d{4}+[-]\\d{1,2}+[-]\\d{1,2}+ " );
Matcher startMacher = pattern.matcher(startDate);
Matcher endMacher = pattern.matcher(endDate);
if ( ! startMacher.matches() || ! endMacher.matches() ){
return true ;
}
return false ;
}
{
Pattern pattern = Pattern.compile( " \\d{4}+[-]\\d{1,2}+[-]\\d{1,2}+ " );
Matcher startMacher = pattern.matcher(startDate);
Matcher endMacher = pattern.matcher(endDate);
if ( ! startMacher.matches() || ! endMacher.matches() ){
return true ;
}
return false ;
}
4:判断两个时间的大小(DATE-String)
code
private
boolean
judgeDate()
{
Date nowDate = new Date();
Date startFormat = null ;
Date endFormat = null ;
SimpleDateFormat dateFormat = new SimpleDateFormat( " yyyy-MM-dd " );
try {
startFormat = dateFormat.parse(startDate);
endFormat = dateFormat.parse(endDate);
} catch (ParseException e) {
e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates.
}
if (startFormat.getTime() > endFormat.getTime()) { return true ; }
if (endFormat.getTime() > nowDate.getTime()){ return true ; }
return false ;
{
Date nowDate = new Date();
Date startFormat = null ;
Date endFormat = null ;
SimpleDateFormat dateFormat = new SimpleDateFormat( " yyyy-MM-dd " );
try {
startFormat = dateFormat.parse(startDate);
endFormat = dateFormat.parse(endDate);
} catch (ParseException e) {
e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates.
}
if (startFormat.getTime() > endFormat.getTime()) { return true ; }
if (endFormat.getTime() > nowDate.getTime()){ return true ; }
return false ;
5:Calendar简单操作
Calendar cal=Calendar.getInstance //使用默认时区默认语言获得一个日历
cal.set(Calendar.YEAR,"1999") //替换为制定
cal.getActualMaximum(Calendar.DATE)//取得DATE可能的最大值