0
System.out.println(
  String.format(
     "You are %s weeks, and %s days pregnant", weeks , days ));
4

3 回答 3

2

如果您正在寻找两个日期之间的天数差异 -

public int daysBetween(Date d1, Date d2){
 return (int)( (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
 }

星期 -

public int weeksBetween(Date d1, Date d2){
 return (int)( (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24 * 7));
 }
于 2012-10-29T06:17:48.457 回答
0

使用java.util.Calendar

t.get(Calendar.DAY_OF_MONTH)     // --- int value of the day of the month (1-31)



t.get(Calendar.DAY_OF_WEEK)      // --- int value of the day of the week (0-6)
于 2012-10-29T06:18:53.683 回答
0

这样做

int num ; // no. of days
int weeks ; // no of weeks
//initialise num 
weeks = num/7;
days = num % 7;
System.format("no of weeks"+weeks+"no of days"+days); 
于 2012-10-29T06:21:04.663 回答