1

我正在使用 CVS 日志阅读器对格式进行一些验证。CVS 迁移后,我收到以下错误:

java.text.ParseException: Unparseable date: "2011/05/30 08:27:24"

经过调查,我认为 CVS 日志文件中的日期格式已从 YYYY-MM-dd 更改为 YYYY/MM/dd。因此验证失败。

CVS 日志的早期格式是

RCS file: /opt/cvsrepositories/demo/Demo/source/demo_search/.classpath,v
Working file: source/demo_search/.classpath
head: 1.1
branch:
locks: strict
access list:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
----------------------------
revision 1.1
date: 2014-07-14 09:50:57 +0000;  author: Dev.User;  state: Exp;  commitid: 62ee53c3a7d54567;
first version of the search module
=============================================================================

现在,它已更改为:

RCS file: /opt/cvsrepositories/demo/Demo/source/demo_search/.classpath,v
Working file: source/demo_search/.classpath
head: 1.1
branch:
locks: strict
access list:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
----------------------------
revision 1.1
date: 2014/07/14 09:50:57 +0000;  author: Dev.User;  state: Exp;  commitid: 62ee53c3a7d54567;
first version of the search module
=============================================================================

我检查了 CVS 手册,但无法在日志中格式化日期格式。

迁移的机器具有与旧机器相同的设置。

4

3 回答 3

1

在调查了更多之后,我发现问题出在 CVS 版本上。迁移的机器的版本为1.11.x但是,早期机器的 cvs 版本为1.12.x. 更新版本后,问题已解决。

由于最新版本支持date as in ISO8601 format. DateFormat=iso8601CVSROOT\config 中有一个属性

于 2016-02-23T15:28:19.120 回答
0

如果你正在开发你的阅读器,你需要使用这样的解析器:

 String strDate = "2011/05/30 08:27:24";
 SimpleDateFormat parserSDF=new SimpleDateFormat("YYYY/mm/dd HH:mm:ss");
 Date date = parserSDF.parse(formattedDate);
于 2016-02-22T11:07:35.247 回答
0

尝试在您的代码中使用此方法:

    private final static SimpleDateFormat OLD_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private final static SimpleDateFormat NEW_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

    public static Date parseDate(String date){
           Date parsedDate;
           try {
               log.debug("Try to parse date using old format");
               parsedDate = OLD_FORMAT.parse(date);
               log.debug("Parsed date using old format");
          } catch (ParseException e) {
               log.debug("Failed while parsed date using old format");
               try {
                   log.debug("Try to parse date using new format");
                   parsedDate = NEW_FORMAT.parse(date);
                   log.debug("Parsed date using new format");
               } catch (ParseException e) {
                   throw new IllegalStateException("Format of 'date' parameter must be yyyy-MM-dd HH:mm:ss or yyyy/MM/dd HH:mm:ss");
               }
          }
          return parsedDate;
     }
于 2016-02-22T11:10:30.143 回答