1. Structure diagram
The intermediate class just gets the current time long type
On the left is the year, month, day or something
The right side is the date format class string and time object conversion (sdf.format(date) sdf.parse(str))
2 The following code can show the conversion process from simpledateformat to date to calendar:
// Purpose: Get the week interval between two dates Date date = new Date() ; Calendar calendarNow = Calendar.getInstance(); int nowweek = calendarNow.get(calendarNow.WEEK_OF_YEAR); // 3 System.out.println("nowweek " + nowweek); // The current time is 2017-12-05, the result is 49, a year is 52 weeks, 52 - 49 + 7 = 10 weeks SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar1 = Calendar.getInstance(); Date date1; try { date1 = sdf.parse("2018-02-14"); calendar1.setTime(date1); int week1 = calendar1.get(calendar1.WEEK_OF_YEAR); // result is 7 System.out.println(week1); } catch (ParseException e) { e.printStackTrace (); }