我正在研究CVS日志读取器,以便对格式进行一些验证。在CVS迁移之后,我得到以下错误:
java.text.ParseException: Unparseable date: "2011/05/30 08:27:24"经过调查,我会把CVS日志文件中的日期格式从YYYY 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手册,但是没有办法在日志中格式化日期格式。
迁移的机器具有与每台旧机器相同的设置。
发布于 2016-02-23 15:28:19
在调查了更多之后,我发现问题在于CVS版本。迁移后的机器的版本为1.11.x,而早期的机器则将cvs版本作为1.12.x。更新版本后,问题得到了解决。
最新版本支持date as in ISO8601 format。CVSROOT\config中有一个属性DateFormat=iso8601
发布于 2016-02-22 11:07:35
如果您正在开发您的读取器,则需要使用如下解析器:
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-22 11:10:30
尝试在代码中使用此方法:
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;
}https://stackoverflow.com/questions/35551818
复制相似问题