Hi i'm a java student beginner I can't get how to input by console a date using GregorianCalendar and print it like: Input: 12/10/1994 Output: 12/10/1994

有帮助吗?

解决方案

here you go

String format="MM/dd/yyyy";

Scanner sc=new Scanner(System.in);
String input=sc.nextLine();//now the program waits for input
Date d= new SimpleDateFormat("MM/dd/yyyy").parse("12/10/1994");
Calendar cal=Calendar.getInstance();
cal.setTime(d);

String output=new SimpleDateFormat(format).format(cal.getTime());

cal is your gregorian calendar.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top