Date and Time in ADF
2009-05-15 21:26
337 查看
【1】、How to Access the Current Date and Time
You might find it useful to reference the current date and time in your entity object
business logic. Example 9–17 shows a helper method you can use to access the current
date without any time information.
Example 9–17 Helper Method to Access the Current Date with No Time
/*
* Helper method to return current date without time
*
* Requires import: oracle.jbo.domain.Date
*/
protected Date getCurrentDate() {
return new Date(Date.getCurrentDate());
}
Example 9–18 Helper Method to Access the Current Date with Time
/*
* Helper method to return current date with time
*
* Requires imports: oracle.jbo.domain.Date
* java.sql.Timestamp
*/
protected Date getCurrentDateWithTime() {
return new Date(new Timestamp(System.currentTimeMillis()));
}
【2】、oracle.jbo.domain.Date用法小结
oracle.jbo.domain.Date继承了oracle.sql.DATE,具有方法public java.sql.Date dateValue()。测试例子如下:
package test;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import oracle.jbo.domain.Date;
public class TestDate {
public TestDate() {
}
private Date str2Date(String strDate) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
java.util.Date date = sdf.parse(strDate);
Timestamp timestamp = new Timestamp(date.getTime());
Date returnDate = new Date(timestamp);
return returnDate;
}
//测试带时间的日期
public void testTime(){
try {
Date d = str2Date("2005-10-31 15:46");
System.out.println("2005-10-31 15:46 TO:" + d);
} catch (Exception ex) {
ex.printStackTrace();
}
}
//测试不带时间的日期
public void testDateWithoutTime(){
GregorianCalendar gc = new GregorianCalendar();
gc.set(2005,11,1); //2005年12月1日。0:1月;1:2月 以此类推。
java.util.Date date = gc.getTime();
Date returnDate = new Date(new java.sql.Date(date.getTime()));
System.out.println(returnDate);
}
public static void main(String[] args) {
TestDate testDate = new TestDate();
testDate.testTime();
//OUTPUT: 2005-10-31 15:46 TO:2005-10-31 15:46:00.0
testDate.testDateWithoutTime();
//OUTPUT: 2005-12-01
}
}
You might find it useful to reference the current date and time in your entity object
business logic. Example 9–17 shows a helper method you can use to access the current
date without any time information.
Example 9–17 Helper Method to Access the Current Date with No Time
/*
* Helper method to return current date without time
*
* Requires import: oracle.jbo.domain.Date
*/
protected Date getCurrentDate() {
return new Date(Date.getCurrentDate());
}
Example 9–18 Helper Method to Access the Current Date with Time
/*
* Helper method to return current date with time
*
* Requires imports: oracle.jbo.domain.Date
* java.sql.Timestamp
*/
protected Date getCurrentDateWithTime() {
return new Date(new Timestamp(System.currentTimeMillis()));
}
【2】、oracle.jbo.domain.Date用法小结
oracle.jbo.domain.Date继承了oracle.sql.DATE,具有方法public java.sql.Date dateValue()。测试例子如下:
package test;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import oracle.jbo.domain.Date;
public class TestDate {
public TestDate() {
}
private Date str2Date(String strDate) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
java.util.Date date = sdf.parse(strDate);
Timestamp timestamp = new Timestamp(date.getTime());
Date returnDate = new Date(timestamp);
return returnDate;
}
//测试带时间的日期
public void testTime(){
try {
Date d = str2Date("2005-10-31 15:46");
System.out.println("2005-10-31 15:46 TO:" + d);
} catch (Exception ex) {
ex.printStackTrace();
}
}
//测试不带时间的日期
public void testDateWithoutTime(){
GregorianCalendar gc = new GregorianCalendar();
gc.set(2005,11,1); //2005年12月1日。0:1月;1:2月 以此类推。
java.util.Date date = gc.getTime();
Date returnDate = new Date(new java.sql.Date(date.getTime()));
System.out.println(returnDate);
}
public static void main(String[] args) {
TestDate testDate = new TestDate();
testDate.testTime();
//OUTPUT: 2005-10-31 15:46 TO:2005-10-31 15:46:00.0
testDate.testDateWithoutTime();
//OUTPUT: 2005-12-01
}
}
相关文章推荐
- Date and Time in PeopleCode
- Date and Time in C++
- Date and Time Representation in Python
- Date and Time Representation in Python
- date and time in Android
- [原] XAF How to see and edit the time part in the DatePropertyEditor for the System.DateTime property
- Date and Time in C++
- Date and Time Arithmetic in JScript zz
- [76] Changing appointments_What time and date did we finally meet?
- Date/Time Support in NHibernate
- [React Intl] Format Date and Time Using react-intl FormattedDate and FormattedTime
- How to enable time stamps for logs in 'dmesg' on Gaia and SecurePlatform
- Custom Date and Time Format Strings
- Strong Authentication with One-Time Passwords in Windows 7 and Windows Server 2008 R2
- 在PL/SQL里直接插入日期时提示 is not a valid date and time的解决方法
- ISO 8601: Delphi way to convert XML date and time to TDateTime and back (via: Stack Overflow)
- System.currentTimeMillis,getTimeInMillis与new Date().getTime获取当前时间戳耗时比较
- System.currentTimeMillis,getTimeInMillis与new Date().getTime获取当前时间戳耗时比较
- 在Snmp++中处理DateAndTime类型数据
- 解决PLSQL提示 is not a valid date and time