为什么解析异常线程“main”中的异常java.text.ParseException:Unparseable date:“Thu Jan 24 00:00:00 EET 2018

时间:2015-12-24 11:36:37

标签: parseexception

这个程序应该减去2天tare3和tare4。 tare3从当前日期(从系统)开始,从文本文件(元素[3])中获取tare4值,当我将字符串(元素[3])解析为日期(tare4)时,它给出了`%parseexception 保存在文件中的日期看起来像(1月24日00:00:00 EET 2018)

package javaapplication3;        
import java.io.*;            `     `
import java.util.*;                  
import java.text.*;

public static void main(String[] args) throws ParseException, FileNotFoundException {
    private  static String tare5 = new String();
    static String tare2 = new String ();

    DateFormat dateFormat = new SimpleDateFormat(" dd MMM yyyy  ",Locale.ENGLISH );
    Calendar cal = Calendar.getInstance();
    Date tare4 =  new Date (); 
    tare5 = dateFormat.format(cal.getTime());
    Date  tare3 = dateFormat.parse(tare5);

    Scanner scanner;
    File Myfile =  new File("C:\\Users\\mido\\Documents\\NetBeansProjects\\JavaApplication3\\src\\javaapplication3\\products.txt");
    scanner = new Scanner (Myfile);


    while (scanner.hasNext()){

        String line = scanner.nextLine();
        StringTokenizer x = new StringTokenizer(line,"~");
        String [] element= new String [7]; 
        int counter = 0 ;

        while (x.hasMoreElements())
        {
            element[counter]=(String)x.nextElement();
            counter ++;

        }
        tare4 = dateFormat.parse(element[3]);

        if (tare4.getTime()>= tare3.getTime() )
        {
            System.out.println(element[1]+"is expired");
        }
        else {
            long def = tare3.getTime()- tare4.getTime();
            System.out.println(element[1]+"has"+def+"to expire");}
        }
   }

0 个答案:

没有答案