Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: How to verify If a date is before another date

Java: How to verify If a date is before another date
{filelink=5544}

import java.util.Calendar;
import java.util.Date;
public class DateBefore
{
  public static void main(String[] args)
  {
    Date today = new Date();
    Calendar calendar = Calendar.getInstance();
    //get date of yesterday
    calendar.add(Calendar.DATE, -1);
    Date yesterday = calendar.getTime();
    if (yesterday.before(today))
    {
      System.out.println(yesterday + " is before " + today);
    }
  }
}

No comments yet.

Leave a Comment