获取货件的详细信息以及预计送达日期。还获取该货件可用的货件状态数量,即中间遍历的数量。编写一个程序来比较货件最终状态的预期日期和货件的实际预期日期,并显示货件是否“按时”、“早于”或“晚于”预期日期到达。
public class ShipmentMain {
public static void main(String[] args) {
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
System.out.println("Enter the shipment details :");
Scanner sc = new Scanner(System.in);
String userDeatil = sc.next();
String[] s = userDeatil.split(",");
Shipment shipment = new Shipment();
ShipmentStatus status = new ShipmentStatus();
for (int j = 0; j < s.length; j++) {
if (j == 0) {
shipment.setid(s[j]);
} else if (j == 1) {
shipment.setsourcePort(s[j]);
} else if (j == 2) {
shipment.setdestinationPort(s[j]);
} else if (j == 3) {
shipment.setexpectedDeliveryDate(s[j]);
} else if (j == 4) {
shipment.setcustomerName(s[j]);
}
}
}
}
示例输入和输出 1:
Enter the shipment details :
STAJU01,Hong Kong,Cochin,20-05-2017,karthick
我无法输入日期字段。请指导我如何输入此内容。
最佳答案
您可以从字符串中删除前两个字符并保存它,将值解析为 int 或其他类型。然后你可以剪掉“-”字符并继续下一步到 int Chars。最后你需要截掉四位数字。之后,您可以轻松地将其添加到您的日期并与其他日期进行比较。 (例如 Date.Format.SHORT)
关于java - 如何在另一个注释中创建和使用具有给定日期的 DateFormat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63264779/