简体   繁体   English

java.text.ParseException:无法解析的日期:“ 11/11/2014”

[英]java.text.ParseException: Unparseable date: “11/11/2014”

I am trying to get the difference betweek to dates 我正在努力使betweek与众不同

String start_date, end_date;
    System.out.println("Date Format: MM/DD/YYYY hh:mm:ss (24-hour format)");
    System.out.print("Start Date and Time: ");
    start_date = cin.next();
    System.out.print("End Date and Time: ");
    end_date = cin2.next();
    SimpleDateFormat date_format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    Date date1 = null, date2 = null;
    try
    {
        date1 = date_format.parse(start_date);
        date2 = date_format.parse(end_date);long diff = date1.getTime() - date2.getTime();
    long diffSeconds = diff / 1000 % 60;
    long diffMinutes = diff / (60 * 1000) % 60;
    long diffHours = diff / (60 * 60 * 1000) % 24;
    long diffDays = diff / (24 * 60 * 60 * 1000);
    System.out.print(diffDays + " days, ");
    System.out.print(diffHours + " hours, ");
    System.out.print(diffMinutes + " minutes, ");
    System.out.print(diffSeconds + " seconds.");
    }
    catch(Exception ex)
    {
        System.out.println(ex);
    }

I keep on getting this error 我不断收到这个错误

Date Format: MM/DD/YYYY hh:mm:ss (24-hour format)
Start Date and Time: 11/11/2014 11:11:11
End Date and Time: 11/21/2014 11:11:11
java.text.ParseException: Unparseable date: "11/11/2014"

please help me 请帮我

Notice your output 注意您的输出

Start Date and Time: 11/11/2014 11:11:11
...
java.text.ParseException: Unparseable date: "11/11/2014"

You entered 你登录了

11/11/2014 11:11:11

but only tried to parse 但只是试图解析

11/11/2014

Scanner#next() used here 这里使用的Scanner#next()

start_date = cin.next();

tokenizes on whitespace (by default). 标记空白(默认情况下)。 Use Scanner#nextLine() to get the full line. 使用Scanner#nextLine()获取完整行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.text.ParseException:无法解析的日期:“2020 年 3 月 11 日星期三” - java.text.ParseException: Unparseable date: "Wed Mar 11 2020" java.text.ParseException:无法解析的日期:“11:49:28 முற்பகல்” - java.text.ParseException: Unparseable date: "11:49:28 முற்பகல்" java.text.ParseException:无法解析的日期:“ 06-DEC-11” - java.text.ParseException: Unparseable date: “06-DEC-11” 我得到了java.text.ParseException:无法解析的日期:“”,最后扩展了零,例如:-2014-11-26 12:22:44.0 - I got java.text.ParseException: Unparseable date: “” with extending zero at last eg:- 2014-11-26 12:22:44.0 java.text.ParseException:无法解析的日期:“01-02-2014” - java.text.ParseException: Unparseable date: “01-02-2014” java.text.ParseException:无法解析的日期:“ 2014/02/20” - java.text.ParseException: Unparseable date: “2014/02/20” java.text.ParseException:无法解析的日期:“ 2018年10月7日,星期日,11:00 PM” - java.text.ParseException: Unparseable date: “11:00 PM, Sun 07 Oct 2018” java.text.ParseException:无法解析的日期:“ CET 2012年1月11日星期三00:00:00” - java.text.ParseException: Unparseable date: “Wed Jan 11 00:00:00 CET 2012” java.text.ParseException:无法解析的日期:“ 2012年1月11日08:00:00” - java.text.ParseException: Unparseable date:“01/11/2012 08:00:00” java:java.text.ParseException:无法解析的日期 - java : java.text.ParseException: Unparseable date
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM