0%
1 2 3 4
| Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy"); String dateString = dateFormat.format(date); System.out.println(dateString);
|
get date from date string
1 2 3 4 5 6 7 8 9
| String dateString2 = "2019-03-05"; DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd"); Date date2 = null; try { date2 = dateFormat2.parse(dateString2); } catch (ParseException e) { e.printStackTrace(); } System.out.println(date2);
|
Calendar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
Calendar calendar = new GregorianCalendar(2019, Calendar.MARCH, 6); System.out.println(calendar.getTime());
Calendar calendar2 = new GregorianCalendar(); calendar2.set(Calendar.YEAR, 2019); calendar2.set(Calendar.MONTH, Calendar.APRIL); calendar2.set(Calendar.DATE, 15); calendar2.set(Calendar.HOUR_OF_DAY, 10); System.out.println(calendar2.getTime());
Calendar calendar3 = new GregorianCalendar(); calendar3.setTime(new Date()); System.out.println(calendar3.getTime());
calendar.add(Calendar.MONTH, 10); calendar.add(Calendar.DATE, -10);
|