Skip to Content
Java™ Phrasebook
book

Java™ Phrasebook

by Timothy Fisher
November 2006
Intermediate to advanced
224 pages
3h 29m
English
Sams
Content preview from Java™ Phrasebook

Comparing Dates

if (date1.equals(date2)) {
											System.out.println("dates are the same.");
											}
											else {
											if (date1.before(date2)) {
											System.out.println("date1 before date2");
											}
											else {
											System.out.println("date1 after date2");
											}
											}

In this phrase, we make use of the equals() and before() methods of the Date class. The equals() method will return true if the data values are the same; otherwise it will return false. The dates must be the same down to the millisecond in order for the equals() method to return true. The before() method returns true if the date on which it is called occurs before the date passed as a parameter to this method.

The Date class also has an after() method, which is used similarly to the before() method to determine if the date on which ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ruby Phrasebook

Ruby Phrasebook

Jason Clinton
Wicked Cool Java

Wicked Cool Java

Brian D. Eubanks
Just Java™ 2

Just Java™ 2

Peter van der Linden
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz

Publisher Resources

ISBN: 0768668255Purchase book