1000 Java Tips ebook
Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!.
How do I compare two dates and times, date between dates, time between times and
JavaFAQ Home » General Java
Question: How do I compare two dates and times, date between dates and so on.
Answer: Almost every month in my daily Java programming work I have this problem - to compare two or many dates or times.
Dates, Calendars are not an easy task to work with. Simple example: never do assume that all the days are 24 hours long. They are not. Some days are 25 and some 23 hours. Seems simple and obvious? Actually not. Most of people forget about it and get troubles twice a year
I collected more than 50 different only working Java code examples with Date class: everything from time, day, month, date, calendar to time synchronizing on computers by Java program (time servers and clients even). In the examples below you can see how this functionality can be used in different areas - applets, files, sound, beans, databases.
Sixth months ago the new section was started on this site - "Only working Java Code Examples". All the examples are grouped by Java technology (J2EE, J2SE, J2ME, etc.) and can be searched by powerful search engine of the site.
Look at all described above code examples here:
Date / Time Example
Getting and Setting the Modification Time of a File or Directory
Beep / Date Example
Java Statement Runner
Trivial class to show use of Date & Calendar objects
Show dates before 1970, in JDK1.0/1.1 when Date was broken
Show some date uses
Create SimpleDateFormats from a string read from a file
DateDiff -- compute the difference between two dates
An Applet to display the current time
The Date we are about to format
Read a file of reminders, run each when due using java.util.Timer
UDP Time Client
Dayclient and Dayserver - implement the Unix 'daytime' protocol.
Try Date Format - enter a time value and a SimpleDateFormat specification.
Last 24 (retrieves file if it's modified since ...)
Clock Label Test
And more examples here-> Date and here Calendar
Printer Friendly Page
Send to a Friend
Search here again if you need more info!