Choose Your Language

Friday 28 June 2013

Java Program to print Yesterdays Date and Time

import java.util.Calendar;
import java.util.Date;

public class YesterdaysDateTime {
    public static void main(String a[]){
        Calendar calendar = Calendar.getInstance();
        Date today = calendar.getTime();
        calendar.add(Calendar.DAY_OF_YEAR, -2);
        Date yesterday = calendar.getTime();    
        System.out.println("Today's Date Time is  "+today);
        System.out.println("Yesterdays's Date Time is "+yesterday);          

    }
}

1 comment: