【发布时间】:2018-01-04 08:18:54
【问题描述】:
import java.text.SimpleDateFormat;
import java.util.Date;
public class Rate_Per_Hour {
public static void main(String[] args) {
String TimeStart = "09.30.00 am";
String TimeEnd= "10.10.00 am";
SimpleDateFormat format = new SimpleDateFormat("hh.mm.ss a");
int total=0;
Date d1 = null;
Date d2 = null;
try {
d1 = format.parse(TimeStart);
d2 = format.parse(TimeEnd);
long diff = d2.getTime() - d1.getTime();
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffMinutes = diff / (60 * 1000) % 60;
if (diffMinutes <= 30) {
total = 20;
}
else if (diffHours <=1){
total = 35;
}
System.out.println("Rs." +total);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
我想要这样的输出: (每小时固定费率为 35 卢比)
30 分钟 = 20 卢比
40 分钟 = Rs.25 等等......
1 小时 = 35 卢比
1 小时 10 分钟 = 40 卢比
请帮助我,弄清楚我该怎么做。
【问题讨论】:
-
你得到了什么输出?