在用Eclipse Kepler自动生成日期注释的时候,中文的日期格式一直不能让人满意。但在Java中也就算了,今晚用Eclipse做Python开发。出现中文导致编译无法进行。然后就开始解决日期格式化问题。
首先参考:http://www.cnblogs.com/hoojo/archive/2011/03/21/1990070.html
http://www.coderli.com/eclipse-template-variable
但是,因为英文太差,在http://wiki.eclipse.org/index.php/CVS_Howto中找不到下载地址。于是,用jd-gui反编译org.eclipse.text_3.5.300.v20130515-1451.jar。
按照上述链接文章中的做法,修改如下:
在org.eclipse.jface.text.templates.GlobalTemplateVariables类中做如下修改:
public class GlobalTemplateVariables$Date extends SimpleTemplateVariableResolver
{
public GlobalTemplateVariables$Date()
{
super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date"));
}
protected String resolve(TemplateContext context) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return df.format(new Date());
}
}
public class GlobalTemplateVariables$Time extends SimpleTemplateVariableResolver
{
public GlobalTemplateVariables$Time()
{
super("time", TextTemplateMessages.getString("GlobalVariables.variable.description.time"));
}
protected String resolve(TemplateContext context)
{
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
return df.format(new Date());
}
}
因为是反编译的,代码本身就会报错。还好的就是GlobalTemplateVariables中import的类不多,就ibm的两个类。在网络上查询,获得这两个类的源代码(http://opensourcejavaphp.net/java/icu4j/com/ibm/icu/util/Calendar.java.html和http://opensourcejavaphp.net/java/icu4j/com/ibm/icu/text/DateFormat.java.html),拷贝到项目中。编译通过。
发现:
直接将这两个class文件覆盖掉org.eclipse.text_3.5.300.v20130515-1451.jar中的文件。
重启Eclipse。