1:
java.sql.Timestamp a = new java.sql.Timestamp(System.currentTimeMillis());
2:
java.util.Date a = new java.util.Date();
theDate=new java.util.Date();//得到当前的日期和时间,如 2003-06-03 08:00:00
3:
java.util.Date a;
a.setTime(System.currentTimeMillis());
4:
currTime=new java.sql.Time(new java.util.Date().getTime());//得到当前时间。
如 08:00:00
currDate=new java.sql.Date(new java.util.Date().getTime());//得到当前日期。
如 2003-06-03
5:
Date date = Calendar.getInstance().getTime();
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd HH:MM:SS ");
String sDate = sdf.format(date);
6:
Calendar todaysDate = new GregorianCalendar();
year = todaysDate.get(Calendar.YEAR);
month = todaysDate.get(Calendar.MONTH) + 1;
day = todaysDate.get(Calendar.DAY_OF_MONTH);
hourOfDay = todaysDate.get(Calendar.HOUR_OF_DAY); // 24小时制
hour = todaysDate.get(Calendar.HOUR); // 12小时制
minute = todaysDate.get(Calendar.MINUTE);
second = todaysDate.get(Calendar.SECOND);
7: Date(int year, int month, int date)
... 使用api, 查看Date constructor.
Deprecated. As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date)
or GregorianCalendar(year + 1900, month, date)
.
Result: Tue Feb 04 00:00:00 CST 1919
得到指定时间:
System.out.println(new GregorianCalendar(19 + 1900, 1, 4,9,9,9).getTime());
Result: Tue Feb 04 09:09:09 CST 1919
8:SimpleDateFormat constructor