修改Eclipse注释里的${Date}变量格式

1.eclipse3.3里${date}日期格式为:
Java代码 复制代码
  1. Jan 8, 2008  

不是很习惯,如果想改变这种格式,比如想改为:
Java代码 复制代码
  1. 2008-1-8  
这样的格式,则可以通过下面的方式

2.从http://wiki.eclipse.org/index.php/CVS_Howto下载eclipse的源码,主要下载org.eclipse.text包下的类

3.找到org.eclipse.jface.text.templates.GlobalTemplateVariables这个类,然后打开进行修改。找到代码:
Java代码 复制代码
  1.   
  2. public static class Date extends SimpleTemplateVariableResolver {   
  3.         /**
  4.           * Creates a new date variable
  5.           */  
  6.         public Date() {   
  7.             super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$   
  8.          }   
  9.         protected String resolve(TemplateContext context) {   
  10.             return DateFormat.getDateInstance().format(new java.util.Date());   
  11.          }   
  12.      }  


然后修改为:

Java代码 复制代码
  1.   
  2. public static class Date extends SimpleTemplateVariableResolver {   
  3.         /**
  4.           * Creates a new date variable
  5.           */  
  6.         public Date() {   
  7.             super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$   
  8.          }   
  9.         protected String resolve(TemplateContext context) {   
  10. //           return DateFormat.getDateInstance().format(new java.util.Date());   
  11.             final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");     
  12.             return df.format(new java.util.Date());     
  13.          }   
  14.      }  



然后再将其重新编译打包即可。
最后覆盖掉eclipse\plugins下的org.eclipse.text_3.3.0.v20070606-0010.jar这个jar包(org.eclipse.text_XXXX.jar包),只是日期不同而已。
转载:http://ttitfly.javaeye.com/blog/154044
类别:Eclipse 查看评论
原文地址:https://www.cnblogs.com/dorothychai/p/2268222.html