aspose file tools*
The moose likes JSF and the fly likes Custom Event Calendar Date Format Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Custom Event Calendar Date Format Problem" Watch "Custom Event Calendar Date Format Problem" New topic
Author

Custom Event Calendar Date Format Problem

Scott Stephens
Greenhorn

Joined: Jun 25, 2011
Posts: 23

I realize this isnt strictly a JSF Problem, but it is in a backing bean that is called by my JSF App.
My problem is that when I compare :

if (dt == result)

dt has the value 2012-11-02 and result has Fri Nov 02 20:29:23 CET 2012 even though I formatted it with SimpleDateFormat.
the static variable ferienTage is an array of holidays that is supposed to be valid for any year. The function compares the parameter dt to the array and returns
true/false if it is a holiday.
Why is there a difference. Both Date objects have been instansiated and initialized.

Maybe someone can help here.
Scott Stephens
Greenhorn

Joined: Jun 25, 2011
Posts: 23

For anyone looking for an example how to compare dates, the following code now does it:
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

The only thing more treacherous than dates when it comes to comparison are floating-point numbers. This is especially true when you read/write them from a database, where the granularity of the date/time objects doesn't correspond exactly to the granularity of the Java temporal objects.

A standard (not high-definition) java.util.Date or java.sql.Date is internally defined as the number of milliseconds since midnight Monday January 1, 1970. To determine whether two dates are the same day mathematically, extract the millisecond value from the date object as a long integer and slice off the fractional day part:


Or, if you prefer, don't multiply back and just count the actual days:


MS_PER_DAY is, of course 1000 (ms) * 60 (sec/minute) * 60 (min/hr) * 24 (hr/day), as a static long value. NOT an int!

In reality, there are somewhat arbitrary "leap seconds" so this isn't an astronomically precise way of doing things, but it's close enough for most business purposes.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom Event Calendar Date Format Problem
 
Similar Threads
Date Validation
How to Compare two Calendar Objects.
Calendar Class
Date manipulation problem
getting wrong values using matcher.group()