1

I have an Oracle database, in which I have timestamp fields but am not storing the timezone.

A global JSF application we have developed being used across UK, US and Sweden - we agreed that we would save dates with server time, and present dates with server time.

I am creating date stamps simply using new Date() in the managed bean and then storing these in Oracle.

I have a date in Oracle:

21-AUG-13 12.24.13.125000000

I want this date to be presented in JSF. We know it is server time which is UTC+2.

JSF and Primefaces are presenting this as:

21/08/2013 11:24

So seem to be subtracting one hour.

I shelled into the linux instance running tomcat, and "date" gives me:

Thu Sep 19 16:25:45 CEST 2013

And doing a System.out.println for a new Date() instance, I get:

Thu Sep 19 15:25:45

I would have assumed creating a Date() instance in the managed bean would use the date on the linux server hosting tomcat, but is one hour behind...

I know Dates have no timezone component but are assuming UTC....

So I am probably reading back a date which is actually UTC+2 into a date instance, which assumes this is UTC+0...and then somehow JSF, seeing the server is operating at UTC+2, is subtracting 2 hours off to get me back to UTC!!

Any advice on where this is falling down, and why new Date() doesnt match the linux date shell value would be appreciated.

Regards

i

smackenzie
  • 2,880
  • 7
  • 46
  • 99
  • possible duplicate of [How to centralize timezone in JSF?](http://stackoverflow.com/questions/13992916/how-to-centralize-fconvertdatetime-timezone-in-jsf) – BalusC Sep 19 '13 at 14:35
  • a simpler question would be, how do I get JSF to give me the same date as I see in Oracle!! – smackenzie Sep 19 '13 at 14:46
  • Tell JSF which time zone to use. It indeed defaults to UTF as you encountered and as answered in the duplicate. – BalusC Sep 19 '13 at 14:54
  • another possible duplicate: http://stackoverflow.com/questions/12351244/jsf-convertdatetime-renders-the-previous-day/12351693#12351693 – BalusC Sep 19 '13 at 14:55
  • I think my issue is that I am reading back UTC+2 dates from Oracle into Date instances which are assuming UTC+0... – smackenzie Sep 19 '13 at 14:56
  • Now i have an Oracle date stamp (no timestamp) of 20-Sep-2013 being presented by JSF as 19-Sep-2013...what is going on here? – smackenzie Sep 19 '13 at 15:53

1 Answers1

0

OK thanks...this seems to have made things a bit less chaotic as per links:

<context-param>
    <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
    <param-value>true</param-value>
</context-param>

trying to understand whats happening in the flow between oracle to tomcat to jsf though.

I have a date (non timestamped value) in Oracle, being held in a managed bean Date instance of 20-Sep-2013...my tomcat server is UTC+2. JSF is presenting the date as the day before...19-Sep-2013 in my ouputLabel.

tomcat logs

default system timezone is sun.util.calendar.ZoneInfo[id="Europe/Stockholm",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=119,lastRule=java.util.SimpleTimeZone[id=Europe/Stockholm,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]

jsf

    <h:outputLabel value="#{customerTasksBean.travelTask.travelDate}" rendered="#{customerTasksBean.renderTravel}">
        <f:convertDateTime pattern="dd-MMM, yyyy" />
  </h:outputLabel>

Is it that JSF knows my server is UTC+2, so to correct to UTC it subtracts 2 hours off my 20-Sep-2013 date, and pushes it to the previous day during the JSF conversion? In my mind, a date has no UTC component, so why would it try to convert a date which is UTC+0 to anything else?

Regards

i

smackenzie
  • 2,880
  • 7
  • 46
  • 99