public class Date2WeekUntil {
public static String Date2Week(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String format = sdf.format(date);
int year = compareTime(format);
int days = differentDaysByMillisecond(date, new Date());
int weeks = days / 7;
if (year == 0) {
//只计算有几周就好了
return weeks + "周";
} else {
int week = weeks - year * 52;
if (week < 1) {
return year + "年";
}
return year + "年" + week + "周";
}
}
public static int differentDaysByMillisecond(Date date1, Date date2) {
int days = (int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24));
return days;
}
public static void main(String[] args) {
System.out.println(Date2Week(new Date()));
}
}