Eclipse 修改注释的 date time 日期时间格式,即${date}变量格式

Eclipse 修改注释的 date time 日期时间格式,即${date}变量格式

找到eclipse安装目录下面的plugins目录,搜索 org.eclipse.text ,找到一个jar包,

例如我找到的jar包为:org.eclipse.text_3.5.300.v20130515-1451.jar

然后打开它,找到这个类: org.eclipse.jface.text.templates.GlobalTemplateVariables

我们重写这个类就行了。(可反编译,也可以找到源码,源码下载地址为:http://git.eclipse.org/c/platform/eclipse.platform.text.git,下载zip包) PS:如果嫌下载源码包麻烦,我这里贴出这个文件的源码,可以直接用(注:这个类很简单,无多少依赖,所有版本通用,无需担心jar包的版本问题)

/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Sebastian Davids: [email protected] - see bug 25376
 *******************************************************************************/
package org.eclipse.jface.text.templates;

import com.ibm.icu.text.DateFormat;
import com.ibm.icu.util.Calendar;

/**
 * Global variables which are available in any context.
 * <p>
 * Clients may instantiate the classes contained within this class.
 * </p>
 *
 * @since 3.0
 */
public class GlobalTemplateVariables {

	/** The type of the selection variables. */
	public static final String SELECTION= "selection"; //$NON-NLS-1$

	/**
	 * The cursor variable determines the cursor placement after template edition.
	 */
	public static class Cursor extends SimpleTemplateVariableResolver {

		/** Name of the cursor variable, value= {@value} */
		public static final String NAME= "cursor"; //$NON-NLS-1$

		/**
		 * Creates a new cursor variable
		 */
		public Cursor() {
			super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$
			setEvaluationString(""); //$NON-NLS-1$
		}
	}

	/**
	 * The word selection variable determines templates that work on a full
	 * lines selection.
	 */
	public static class WordSelection extends SimpleTemplateVariableResolver {

		/** Name of the word selection variable, value= {@value} */
		public static final String NAME= "word_selection"; //$NON-NLS-1$

		/**
		 * Creates a new word selection variable
		 */
		public WordSelection() {
			super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedWord")); //$NON-NLS-1$
		}
		protected String resolve(TemplateContext context) {
			String selection= context.getVariable(SELECTION);
			if (selection == null)
				return ""; //$NON-NLS-1$
			return selection;
		}
	}

	/**
	 * The line selection variable determines templates that work on selected
	 * lines.
	 */
	public static class LineSelection extends SimpleTemplateVariableResolver {

		/** Name of the line selection variable, value= {@value} */
		public static final String NAME= "line_selection"; //$NON-NLS-1$

		/**
		 * Creates a new line selection variable
		 */
		public LineSelection() {
			super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedLines")); //$NON-NLS-1$
		}
		protected String resolve(TemplateContext context) {
			String selection= context.getVariable(SELECTION);
			if (selection == null)
				return ""; //$NON-NLS-1$
			return selection;
		}
	}

	/**
	 * The dollar variable inserts an escaped dollar symbol.
	 */
	public static class Dollar extends SimpleTemplateVariableResolver {
		/**
		 * Creates a new dollar variable
		 */
		public Dollar() {
			super("dollar", TextTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$
			setEvaluationString("$"); //$NON-NLS-1$
		}
	}

	/**
	 * The date variable evaluates to the current date.
	 */
	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());
		}
	}

	/**
	 * The year variable evaluates to the current year.
	 */
	public static class Year extends SimpleTemplateVariableResolver {
		/**
		 * Creates a new year variable
		 */
		public Year() {
			super("year", TextTemplateMessages.getString("GlobalVariables.variable.description.year")); //$NON-NLS-1$ //$NON-NLS-2$
		}
		protected String resolve(TemplateContext context) {
			return Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
		}
	}

	/**
	 * The time variable evaluates to the current time.
	 */
	public static class Time extends SimpleTemplateVariableResolver {
		/**
		 * Creates a new time variable
		 */
		public Time() {
			super("time", TextTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$
		}

		/**
		 * {@inheritDoc}
		 */
		protected String resolve(TemplateContext context) {
			return DateFormat.getTimeInstance().format(new java.util.Date());
		}
	}

	/**
	 * The user variable evaluates to the current user.
	 */
	public static class User extends SimpleTemplateVariableResolver {
		/**
		 * Creates a new user name variable
		 */
		public User() {
			super("user", TextTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$
		}

		/**
		 * {@inheritDoc}
		 */
		protected String resolve(TemplateContext context) {
			return System.getProperty("user.name"); //$NON-NLS-1$
		}
	}
}

自行拿去修改就行了。改一下Date Time Year就行了,例如,我修改的结果如下:

/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Sebastian Davids: [email protected] - see bug 25376
 *******************************************************************************/
package org.eclipse.jface.text.templates;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * Global variables which are available in any context.
 * <p>
 * Clients may instantiate the classes contained within this class.
 * </p>
 *
 * @since 3.0
 */
public class GlobalTemplateVariables {

	/** The type of the selection variables. */
	public static final String SELECTION= "selection"; //$NON-NLS-1$

	/**
	 * The cursor variable determines the cursor placement after template edition.
	 */
	public static class Cursor extends SimpleTemplateVariableResolver {

		/** Name of the cursor variable, value= {@value} */
		public static final String NAME= "cursor"; //$NON-NLS-1$

		/**
		 * Creates a new cursor variable
		 */
		public Cursor() {
			super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$
			setEvaluationString(""); //$NON-NLS-1$
		}
	}

	/**
	 * The word selection variable determines templates that work on a full
	 * lines selection.
	 */
	public static class WordSelection extends SimpleTemplateVariableResolver {

		/** Name of the word selection variable, value= {@value} */
		public static final String NAME= "word_selection"; //$NON-NLS-1$

		/**
		 * Creates a new word selection variable
		 */
		public WordSelection() {
			super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedWord")); //$NON-NLS-1$
		}
		protected String resolve(TemplateContext context) {
			String selection= context.getVariable(SELECTION);
			if (selection == null)
				return ""; //$NON-NLS-1$
			return selection;
		}
	}

	/**
	 * The line selection variable determines templates that work on selected
	 * lines.
	 */
	public static class LineSelection extends SimpleTemplateVariableResolver {

		/** Name of the line selection variable, value= {@value} */
		public static final String NAME= "line_selection"; //$NON-NLS-1$

		/**
		 * Creates a new line selection variable
		 */
		public LineSelection() {
			super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedLines")); //$NON-NLS-1$
		}
		protected String resolve(TemplateContext context) {
			String selection= context.getVariable(SELECTION);
			if (selection == null)
				return ""; //$NON-NLS-1$
			return selection;
		}
	}

	/**
	 * The dollar variable inserts an escaped dollar symbol.
	 */
	public static class Dollar extends SimpleTemplateVariableResolver {
		/**
		 * Creates a new dollar variable
		 */
		public Dollar() {
			super("dollar", TextTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$
			setEvaluationString("$"); //$NON-NLS-1$
		}
	}

	/**
	 * The date variable evaluates to the current date.
	 */
	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());
		    final SimpleDateFormat df = new SimpleDateFormat(TextTemplateMessages.getString("GlobalVariables.variable.format.date"));
            return df.format(new java.util.Date());
		}
	}

	/**
	 * The year variable evaluates to the current year.
	 */
	public static class Year extends SimpleTemplateVariableResolver {
		/**
		 * Creates a new year variable
		 */
		public Year() {
			super("year", TextTemplateMessages.getString("GlobalVariables.variable.description.year")); //$NON-NLS-1$ //$NON-NLS-2$
		}
		protected String resolve(TemplateContext context) {
//			return Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
		    return Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
		}
	}

	/**
	 * The time variable evaluates to the current time.
	 */
	public static class Time extends SimpleTemplateVariableResolver {
		/**
		 * Creates a new time variable
		 */
		public Time() {
			super("time", TextTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$
		}

		/**
		 * {@inheritDoc}
		 */
		protected String resolve(TemplateContext context) {
		    final SimpleDateFormat df = new SimpleDateFormat(TextTemplateMessages.getString("GlobalVariables.variable.format.time"));
            return df.format(new java.util.Date());
			//return DateFormat.getTimeInstance().format(new java.util.Date());
		}
	}

	/**
	 * The user variable evaluates to the current user.
	 */
	public static class User extends SimpleTemplateVariableResolver {
		/**
		 * Creates a new user name variable
		 */
		public User() {
			super("user", TextTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$
		}

		/**
		 * {@inheritDoc}
		 */
		protected String resolve(TemplateContext context) {
			return System.getProperty("user.name"); //$NON-NLS-1$
		}
	}
}

我改成了使用

import java.text.SimpleDateFormat;

import java.util.Calendar;

并且从properties文件中读取format格式,可以借鉴。

我提供编译好的class文件供大家下载(下载下面的图片,把jpg后缀 改成rar后缀,然后打开),替换到原文件即可。

时间: 2024-12-28 01:27:30

Eclipse 修改注释的 date time 日期时间格式,即${date}变量格式的相关文章

Linux之简单命令之日期时间命令之date,cal,clock ,hwclock和tzselect

一.date命令: 在linux环境中,不管是编程还是其他维护,时间是必不可少的,也经常会用到时间的运算,熟练运用date命令来表示自己想要表示的时间,肯定可以给自己的工作带来诸多方便. 1.命令格式: date [参数]... [+格式] 2.命令功能: date 可以用来显示或设定系统的日期与时间. 3.命令参数: 必要参数: %H 小时(以00-23来表示).  %I 小时(以01-12来表示).  %K 小时(以0-23来表示).  %l 小时(以0-12来表示).  %M 分钟(以00

数据库日期时间显示在页面上格式错误的解决方案

做项目过程中肯定会碰到这样一个问题:在数据库中存的是date或datetime类型的值,从数据库里取出来遍历到页面上显示的是long类型或是GTM类型的日期时间.对于这个问题,经过研究之后有以下结论: 1.hibernate不会出现这样的问题,而mabatis则会出现这个问题. 2.数据库使用date类型的在页面上会显示long类型日期时间,使用datetime类型的在页面上会显示GTM类型日期时间. 因为我用的是mysql数据库,其他的数据库没测试过,所以也不知道其他数据库是怎样的情况,这里就

oracle修改varchar2或nvarchar2类型的时间字段为DATE

ORACLE不区分大小写,且不认识MM,故改为MI,YYYY/MM/DD HH24:MI:SS,为了避免出错,写的时候要大写. start_up_time 类型为DATE类型 completion_time类型为NVARCHAR2类型,值格式为2011-11-23 00:00:00 SQL: update GC_UNDERGROUND set start_up_time = to_date(completion_time,'YYYY/MM/DD HH24:MI:SS'); update GC_U

我使用过的Linux命令之date - 显示、修改系统日期时间

我使用过的Linux命令之date - 显示.修改系统日期时间 本文链接:http://codingstandards.iteye.com/blog/1157513   (转载请注明出处) 用途说明 ate命令可以用来显示和修改系统日期时间,注意不是time命令. 常用参数 格式:date 显示当前日期时间. 格式:date mmddHHMM 格式:date mmddHHMMYYYY 格式:date mmddHHMM.SS 格式:date mmddHHMMYYYY.SS 设置当前日期时间,只有r

我使用过的Linux命令之date - 显示、修改系统日期时间(转)

用途说明 ate命令可以用来显示和修改系统日期时间,注意不是time命令. 常用参数 格式:date 显示当前日期时间. 格式:date mmddHHMM 格式:date mmddHHMMYYYY 格式:date mmddHHMM.SS 格式:date mmddHHMMYYYY.SS 设置当前日期时间,只有root用户才能执行,执行完之后还要执行 clock -w 来同步到硬件时钟. mm为月份,dd为日期,HH为小时数,MM为分钟数,YYYY为年份,SS为秒数. 格式:date +FORMAT

包装类、Date类、SimpleDateFormat类(基本数据类型&lt;--&gt;String&lt;--&gt;日期/时间)

基本数据类型-->String "+"字符串连接符 基本数据类型<--String 基本数据类型 包装类 String-->xxx xxx parseXxx(String s) byte  Byte byte parseByte(String s) short   Short short parseShort(String s) int  Integer int parseInt(String s) long Long long parseLong(String s)

c/c++日期时间处理与字符串string转换

在c/c++实际问题的编程中,我们经常会用到日期与时间的格式,在算法运行中,通常将时间转化为int来进行计算,而处理输入输出的时候,日期时间的格式却是五花八门,以各种标点空格相连或者不加标点. 首先,在c中,是有一个标准的日期时间结构体的,在标准库wchar.h内,我们可以看到结构体tm的声明如下: 1 #ifndef _TM_DEFINED 2 struct tm { 3 int tm_sec; /* seconds after the minute - [0,59] */ 4 int tm_

Java日期时间实用工具类

1.Date (java.util.Date)    Date();        以当前时间构造一个Date对象    Date(long);        构造函数        boolean after(Date when)         测试此日期是否在指定日期之后 boolean before(Date when)         测试此日期是否在指定日期之前 Object clone()         返回此对象的副本 int compareTo(Date anotherDat

Java常用类库之时间操作类——Date、Calendar、DateFormat、SimpleDateFormat及实例操作

学习目标 掌握Date类的使用 可以使用Calendar类取得一个完整的日期 掌握日期格式化的操作 可以使用SimpleDateFormat进行日期的格式化转换操作 编写取得日期的操作类 进一步掌握Calendar类的使用 进一步掌握SimpleDateFormat类的使用 Date类是一个较为常用的类,但是其操作的日期格式会有一些不符合个人要求,而如果想要进一步取得一些自己需要的时间,则可以使用Calendar类. Date类 在java.util包中定义了Date类,Date类本身使用非常简