Friday, July 10, 2015

ADF: Date & Time

Provided different examples to get date & time in ADF.

Groovy:
Current Database Date: DBTransaction.currentDbTime
Current Date: adf.currentDate
Current DateTime: adf.currentDateTime
Add Dates to Current Date: adf.currentDateTime.plus(10)


Java:
Find AM or PM: 
Calendar.getInstance().get(Calendar.AM_PM)
returns 0 for AM & 1 for PM

Get Today's date:
Date d = new Date(Date.getCurrentDate())

Get todays Timestamp:    
Timestamp myTimestamp = new Timestamp((new java.util.Date()).getTime());

Get the database time and set VO attirbute:
vo.setAttribute("OrderDate", ((DBTransactionImpl)getDBTransaction()).getCurrentDbTime());

Get current database time in the middle tier:
oracle.jbo.server.DBTransactionImpl.getCurrentDbTime()

Get current time as java.sql.Date:
new java.sql.Date(((DBTransactionImpl)(this.getDBTransaction())).getCurrentDbTime().getTime());

Get Date value in Page/Fragments:
Add following values to adfc-config.xml or taskflow.xml:

<managed-bean>    
<managed-bean-name>currentDate</managed-bean-name>    
<managed-bean-class>java.util.Date</managed-bean-class>    
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>  

And refer as below
<af:outputText value="#{currentDate}">    
<f:convertDateTime pattern="MM/dd/yyyy" type="date"/>
</af:outputText> 

No comments:

Post a Comment

Provide your thoughts !