我有一個包含一個字段的Oracle數據庫W_PLANNED_DATE: 19/03/2013 10:55:00 (Date)
Java.util.Date VS Java.sql.Date - 日期值不同
在Java中,我把這個值到一個變量:
Date dteBeginOrWaitingItem = orWaitinglist.getWPlannedDate();
value: 2013-03-19
現在,我的時間到底發生了什麼?我需要這個來填充primefaces的schedulecomponent。 我怎樣才能得到一個完整的日期和時間值
eventResourceAvailPerDay.addEvent(new DefaultScheduleEvent(reason, dteBeginOrWaitingItem, dteEndOrWaitingItem, "waitingitem"));
這種方法使事件在12:00 PM
因爲沒有其它的時間或僅僅是00:00:00
我知道如何使用日曆類,但它只是讓我設置日期,時間似乎是空的,但在數據庫視圖中我有一個日期時間值。
爲myBean
import java.util.Date;
@ManagedBean(name="scheduleController")
@SessionScoped
public class ScheduleController implements Serializable {
private Date dteBeginOrWaitingItem, dteEndOrWaitingItem;
//methods
try
{
//eventWaitinglist.clear();
OrWaitinglistDao orWaitinglistDao = new OrWaitinglistDaoImpl();
waitingEvents = orWaitinglistDao.getOrWaitinglistKeysByResource(rKey);
int i = 0;
Iterator<OrWaitinglist> it2 = waitingEvents.iterator();
while (it2.hasNext())
{
orWaitinglist = it2.next();
dteBeginOrWaitingItem = (Date) orWaitinglist.getWPlannedDate();
dteEndOrWaitingItem = orWaitinglist.getWPlannedDate();
//dteEndOrWaitingItem = orWaitinglist.getWPlannedDate();
reason = orWaitinglist.getWDescription();
eventResourceAvailPerDay.addEvent(new DefaultScheduleEvent(reason, dteBeginOrWaitingItem, dteEndOrWaitingItem, "waitingitem"));
i += 1;
System.out.println("EventWaiting: " + i + " " + dteBeginOrWaitingItem + " " + dteEndOrWaitingItem + " " + reason);
}
}
catch(java.util.EmptyStackException Ex)
{
System.out.println(Ex.getMessage());
}
WORKING UPDATE: 豆:
try
{
//eventWaitinglist.clear();
OrWaitinglistDao orWaitinglistDao = new OrWaitinglistDaoImpl();
waitingEvents = orWaitinglistDao.getOrWaitinglistKeysByResource(rKey);
int i = 0;
Iterator<OrWaitinglist> it2 = waitingEvents.iterator();
while (it2.hasNext())
{
orWaitinglist = it2.next();
Long wPlannedDate = orWaitinglist.getWPlannedDate().getTime();
if (wPlannedDate != 0) {
Date wPlannedDateConverted = new Date(wPlannedDate);
dteBeginOrWaitingItem = convertDate(0, 0, wPlannedDateConverted);
dteEndOrWaitingItem = convertDate(orWaitinglist.getWDuration().intValue(), orWaitinglist.getWAdditionalTime().intValue(), wPlannedDateConverted);
}
reason = orWaitinglist.getWDescription();
DefaultScheduleEvent newResourceEvent = new DefaultScheduleEvent(reason, dteBeginOrWaitingItem, dteEndOrWaitingItem, orWaitinglist);
newResourceEvent.setStyleClass("waitingitem");
eventResourceAvailPerDay.addEvent(newResourceEvent);
}
}
catch(java.util.EmptyStackException Ex)
{
System.out.println(Ex.getMessage());
}
public static Date convertDate(Integer wDuration, Integer wAdditionalTime, Date availDate)
{
Calendar cal = Calendar.getInstance();
Integer wAdditionalTimeHours, wAdditionalTimeMinutes;
Integer wDurationHours, wDurationMinutes;
if(wAdditionalTime != 0 || wDuration != 0) {
if (wAdditionalTime !=0) {
wAdditionalTimeHours = (int) Math.floor (wAdditionalTime/60);
wAdditionalTimeMinutes = wAdditionalTime - (wAdditionalTimeHours * 60);
cal.setTime(availDate);
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
cal.add(Calendar.MINUTE, wAdditionalTimeMinutes);
cal.add(Calendar.HOUR_OF_DAY, wAdditionalTimeHours);
}
if (wDuration != 0) {
wDurationHours = (int) Math.floor (wAdditionalTime/60);
wDurationMinutes = wAdditionalTime - (wDurationHours * 60);
cal.setTime(availDate);
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
cal.add(Calendar.MINUTE, wDurationMinutes);
cal.add(Calendar.HOUR_OF_DAY, wDurationHours);
}
} else {
cal.setTime(availDate);
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
}
return cal.getTime();
}
型號更新:
<property name="WPlannedDate" type="timestamp">
<column length="7" name="W_PLANNED_DATE">
<comment>Planned date</comment>
</column>
</property>
嗯,正如我所說,沒有時間在我的日期變量,所以這是有點沒用,因爲它只是返回我的日期0時間:12/02/12-00:00 .. 。 – JeroenVP
如果正在使用的.xml爲休眠變更類型進行時間戳記的日期代替。 '<屬性名=「yourdate」 柱=「YOUR_DATE」 類型=「時間戳」 />' 因此你有時間在你的數據庫,並可以使用簡單日期格式 – Gokhan
omg它的工作!:D會休眠或Java的任何問題,當我嘗試寫在這張表現在?現在只有1個問題我在數據庫中的時間是8:45但在我的變數是7:45,我認爲這與「CET」時區有關,對此有何修正? – JeroenVP