Java日期时间解析

Java日期时间解析,java,parsing,date,time,Java,Parsing,Date,Time,我有以下代码可以简单地将日期和时间解析为一种格式 SimpleDateFormat sdfClient = new SimpleDateFormat("yyyyMMddhhmmss.s"); SimpleDateFormat sdfFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); pmList.add(sdfClient.format(sdfFormat.parse(pmData[k].retrievalTime))); 要将格式更改

我有以下代码可以简单地将日期和时间解析为一种格式

SimpleDateFormat sdfClient = new SimpleDateFormat("yyyyMMddhhmmss.s");
SimpleDateFormat sdfFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");

pmList.add(sdfClient.format(sdfFormat.parse(pmData[k].retrievalTime)));
要将格式更改为sdfClient,但由于某些原因,eclipse会引发错误:

java.text.ParseException: Unparseable date: "20140623135000.0"
at java.text.DateFormat.parse(DateFormat.java:357)
at com.syntronic.client.GenerateCSV.writepmData(GenerateCSV.java:220)
at com.syntronic.client.GenerateCSV.writeMEData(GenerateCSV.java:187)
at com.syntronic.client.GenerateCSV.<init>(GenerateCSV.java:87)
at com.syntronic.client.Client.main(Client.java:213)

有人知道原因吗?

您的格式化程序和解析器混在一起了

pmList.add(sdfClient.format(sdfFormat.parse(pmData[k].retrievalTime)));
基本上说,yyyyMMddhhmmss.s.formatdd/MM/yyyy hh:MM:ss.parse

你想用

pmList.add(sdfFormat.format(sdfClient.parse(pmData[k].retrievalTime)));

相反…

应该是另一种方式:

pmList.add(sdfFormat.format(sdfClient.parse(pmData[k].retrievalTime)));
说明:


我的猜测是pmData[k]持有第一种格式,但您首先将其解析为第二种格式。尝试使用sdfClient和sdfFormat交换调用。pmData[k]数组的类型是什么?parse接受类型字符串作为参数。
pmList.add(
       sdfFormat.format(  <-- Gives a string 23/06/2014 01:50:00
            sdfClient.parse( <-- Gives a Date corresponding to the time 20140623135000.0
                  pmData[k].retrievalTime   <-- Time 20140623135000.0
               )
        )
        );