CVS日志日期格式配置

时间:2016-02-22 10:56:47

标签: java date-format cvs parseexception

我正在使用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手册,但无法格式化日志中的日期格式。

迁移的计算机与旧计算机的设置相同。

3 个答案:

答案 0 :(得分:1)

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

最新版本支持date as in ISO8601 format。 CVSROOT \ config

中有一个属性DateFormat=iso8601

答案 1 :(得分:0)

如果您正在开发阅读器,则需要使用如下解析器:

 String strDate = "2011/05/30 08:27:24";
 SimpleDateFormat parserSDF=new SimpleDateFormat("YYYY/mm/dd HH:mm:ss");
 Date date = parserSDF.parse(formattedDate);

答案 2 :(得分: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;
     }