如何设置Eclipse日期变量格式? [英] How to set the Eclipse date variable format?

查看:229
本文介绍了如何设置Eclipse日期变量格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置可以在Eclipse模板中使用的$ {date}变量的格式?

解决方案

更新2016年2月:






更新2015年7月,6年后:



下面提到的错误似乎在Eclipse 4.x中修复。

< a href =http://stackoverflow.com/users/4132579/eric-wang> Eric Wang 下面的评论

  @date $ { id:date('YYYY-MMM-dd')} $ {time} 




这给我在日食4中的英文日期时间格式。







Eclipse 3.x



Argh!有一个长期的错误只是为了: 错误75981


可以增强 $ {date} 变量以接受一个参数(类似于3.3M1中添加的其他
参数),例如 $ {d:date(format)} ,其中格式 SimpleDateFormat


唯一的选择是修改类 SimpleTemplateVariableResolver (如此线程),从包 org.eclipse.jface.text.templates 。 (您有一个此类扩展的示例)。



线程提及您可以找到课程的来源。

  \eclipse\plugins\org.eclipse.platform .source_3.1.0\src\org.eclipse.text_3.1.0\src.zip 

示例:

  public static class Date extends SimpleTemplateVariableResolver {
/ **
*创建一个新的日期变量
* /
public Date(){
super(date,TextTemplateMessages.getString(GlobalVariables.variable.description.date)); // $ NON-NLS-1 $ // $ NON-NLS-2 $}

protected String resolve(TemplateContext context){
//返回DateFormat.getDateInstance()。format new java.util.Date());
DateFormat df = new SimpleDateFormat(dd / MM / yyyy);
return df.format(new java.util.Date()); }}


How can I set the format for the ${date} variable which can be used in Eclipse templates?

解决方案

Update February 2016: bug 75981 is officially fixed!
See Jmini's answer below


Update July 2015, 6 years later:

The bug mentioned below seems fixed in Eclipse 4.x.
Eric Wang comments below:

@date ${id:date('YYYY-MMM-dd')} ${time} 

this give me English datetime format in eclipse 4.


Original Answer 2009 Eclipse 3.x

Argh! There is a long standing bug just for that: bug 75981

The ${date} variable could be enhanced to accept an argument (similar to other parameterizations added in 3.3M1), e.g. ${d:date(format)}, where format is a pattern for SimpleDateFormat.

The only alternative would be to modify the class SimpleTemplateVariableResolver (as described in this thread), from the package org.eclipse.jface.text.templates. (You have here an example of such an extension).

This thread mentions the sources where you can find the class.

\eclipse\plugins\org.eclipse.platform.source_3.1.0\src\org.eclipse.text_3.1.0\src.zip

Example:

public static class Date extends SimpleTemplateVariableResolver {
/**
* Creates a new date variable
*/
public Date() {
super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$ }

protected String resolve(TemplateContext context) {
    //return DateFormat.getDateInstance().format(new java.util.Date());
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    return df.format(new java.util.Date()); } }

这篇关于如何设置Eclipse日期变量格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆