我正在尝试从用户那里读取日期并传递到 GregorianCalendar 变量。目前我的设置很尴尬,需要逐行读取。你能帮忙想一个在一行内收集输入的解决方案吗?我找到了 SimpleDateFormat 类,但是似乎没有很好地符合这个特定的需求。
Scanner time = new Scanner(System.in)
System.out.println("Type year: ");int y =time.nextInt();
System.out.println("Type month: ");int m =time.nextInt();
System.out.println("Type day: ");int d = time.nextInt();
System.out.println("Type hour: ");int h = time.nextInt();
System.out.println("Type minute: ");int mm = time.nextInt();
GregorianCalendar data = new GregorianCalendar(y,m,d,h,mm);
ISO 8601
定义。这种合理的格式在商业和工业中越来越普遍,并且通常在现代互联网和信息协议中指定。这种格式被Joda-Time和java.time用作生成和解析日期时间值的字符串表示的默认格式。 - Basil Bourque