import java.util.Calendar; import java.util.Date; import java.util.LinkedHashMap; public class Demo { public static void main(String[] argv) { Calendar cal = Calendar.getInstance(); Date date = new Date(); System.out.println("Date = "+date); cal.setTime(date); LinkedHashMap<String, Integer>hashMap = new LinkedHashMap<String, Integer>(); hashMap.put("year", cal.get(Calendar.YEAR)); hashMap.put("month", cal.get(Calendar.MONTH)); hashMap.put("day", cal.get(Calendar.DAY_OF_MONTH)); System.out.println("HashMap (Date) = "+hashMap); hashMap.put("hour", cal.get(Calendar.HOUR_OF_DAY)); hashMap.put("minute", cal.get(Calendar.MINUTE)); hashMap.put("second", cal.get(Calendar.SECOND)); hashMap.put("millisecond", cal.get(Calendar.MILLISECOND)); System.out.println("HashMap (DateTime) = "+hashMap); } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more