File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Util package date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Util package date" Watch "Util package date" New topic
Author

Util package date

prince davies
Ranch Hand

Joined: May 08, 2009
Posts: 74
previousPlanEffectiveDate != null && previousPlanEffectiveDate.after(date)

I am checking previousPlanEffectiveDate with a date selected from calendar.Do I need to format these two dates to call after method of Date?
Do I need to make both the dates have same format(DD/MM/YYYY)?

If two dates return two different format,will after method still check the conditions whether its after or before?

date : Sun Mar 15 00:00:00 PST 2009
Previous Plan EffectiveDate : 2009-05-08 21:00:00.0


previousPlanEffectiveDate != null && previousPlanEffectiveDate.after(date)
2009-05-08 21:00:00.0 != null && (2009-05-08 21:00:00.0)after(Sun Mar 15 00:00:00 PST 2009 )

Will this dates give the desired result? Do I need to format both dates to same format for chacking with after method?
Ifso,how do I format these two dates?

Do both dates need to be in same time zone and hour?

What would be the scenario in which this check will fail for the above case? Some times it fails the check.I cannot figure it out.

Please guide me.

Thanks
p


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41524
    
  53
Date or Calendar objects have no formatting; they can be formatted into string objects, but then you can't apply methods like before/after. So this: "(2009-05-08 21:00:00.0)after(Sun Mar 15 00:00:00 PST 2009)" doesn't make sense because it deals with String objects, not Dates or Calendars.

If you want to consider different time zones then you should use Calendar, not Date - Date has no concept of time zones.
If you have two calendar objects, then they don't need to be in the same time zone in order to be compared - the Calendar class knows how to take that into account.


Ping & DNS - my free Android networking tools app
prince davies
Ranch Hand

Joined: May 08, 2009
Posts: 74
Thanks a lot!

My scenario is comparing two Date objects,not string object using after method.But my concern is whether I need to worry about format of thsese two date objects while comparing with after method? Or after method will not consider the formats of date objects?

Please confirm.

date : Sun Mar 15 00:00:00 PST 2009[Calendar Object = selected from javascript calendar object and assigned to date object]
Previous Plan EffectiveDate : 2009-05-08 21:00:00.0 [assigned to Date Object]

And comparing these two objects using after method.is this returns desired result?

previousPlanEffectiveDate != null && previousPlanEffectiveDate.after(date)
2009-05-08 21:00:00.0 != null && (2009-05-08 21:00:00.0)after(Sun Mar 15 00:00:00 PST 2009 )

these two dates are printed using System.out.prinltn(2009-05-08 21:00:00.0,Sun Mar 15 00:00:00 PST 2009 )

Time Zone is not important in my case.


One question not related to above question
I have one date object and another calender object.Is it possible to compare these two?I do not know the time zone of the date object.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

prince davies wrote:My scenario is comparing two Date objects,not string object using after method.But my concern is whether I need to worry about format of thsese two date objects while comparing with after method? Or after method will not consider the formats of date objects?

Please confirm.

after, before, compareTo, all work on Date objects, and Date objects don't have any formatting. Sure, toString() returns something, but that's just so you see what the Date object means.

One question not related to above question
I have one date object and another calender object.Is it possible to compare these two?I do not know the time zone of the date object.

Calendar has two methods called getTime() and setTime(Date). Your choice which one you want to use


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
prince davies
Ranch Hand

Joined: May 08, 2009
Posts: 74
If you want to consider different time zones then you should use Calendar, not Date - Date has no concept of time zones.
If you have two calendar objects, then they don't need to be in the same time zone in order to be compared - the Calendar class knows how to take that into account.



Question 1)According to your reply,When it comes to the comparison using before(),after(),Date Object and Calendar does not care about the time zones? Is this right?

Question 2)How date objects and calendar objects are compared in java?

Question 3) What algorithm is being used by JAVA API to compare date and claendar objects ?

Question 4) Does JAVA API knocks out the time zone difference ,before comparing date and calendar ojects?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
The answers should be in the Calendar and Date documentation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Util package date