Check This

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Enumeration keys = hash.keys(); while( keys.hasMoreElements() ) { Object key = keys.nextElement(); Object value = hash.

get(key); }

import java.util.Calendar; import java.util.Date; public class DateUtil { public static void main(String[] args) { //Date1 Calendar cal1 = Calendar.getInstance(); cal1.set(1995, 04, 3, 5, 0, 0); Date date1 = cal1.getTime(); //Date2 Calendar cal2 = Calendar.getInstance(); cal2.set(2011, 07, 4, 6, 1, 1); Date date2 = cal2.getTime(); //Time Difference Calculations Begin long milliSec1 = date1.getTime(); long milliSec2 = date2.getTime(); long timeDifInMilliSec; if(milliSec1 >= milliSec2) { timeDifInMilliSec = milliSec1 - milliSec2; } else { timeDifInMilliSec = milliSec2 - milliSec1; } long timeDifSeconds = timeDifInMilliSec / 1000; long timeDifMinutes = timeDifInMilliSec / (60 * 1000); long timeDifHours = timeDifInMilliSec / (60 * 60 * 1000); long timeDifDays = timeDifInMilliSec / (24 * 60 * 60 * 1000); System.out.println("Time differences expressed in various units are given below" ); System.out.println(timeDifInMilliSec + " Milliseconds"); System.out.println(timeDifSeconds + " Seconds"); System.out.println(timeDifMinutes + " Minutes"); System.out.println(timeDifHours + " Hours"); System.out.println(timeDifDays + " Days"); } }

You might also like