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: sdavids@gmx.de - 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: sdavids@gmx.de - 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后缀,然后打开),替换到原文件即可。

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

  1. IntelliJ IDEA如何设置添加类时注释作者信息和日期时间

    IntelliJ IDEA如何设置添加类时注释作者信息和日期时间 如何达到这种效果呢?出现作者自己的信息,通过Idea如下操作: 步骤:1File-->Settings 2.Settings-- ...

  2. linux常用时间命令全集,Linux 指令篇:日期时间排程--date

    Linux 指令篇:日期时间排程--date 名称 : date 使用权限 : 所有使用者 使用方式 : date [-u] [-d datestr] [-s datestr] [--utc] [-- ...

  3. linux date -s日期时间,linux下的date详解

    date:查看或修改系统日期时间 date [OPTION]... [+FORMAT] date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] -d,- ...

  4. Date类(日期时间类)219

    219节课堂笔记 1.概述:表示特定的时间 2.所在的类:java.util.Date(表示时间和日期的类) 类date标识特定的瞬间,精确到毫秒 3.毫秒的换算:1秒=1000毫秒 tips:不可以 ...

  5. 【Java】JDK1.8新特性Date类----日期/时间改进

    一.为什么我们需要新的Java日期/时间API? 1.8之前JDK自带的日期处理类非常不方便,我们处理的时候经常是使用的第三方工具包,比如commons-lang包等.不过1.8出现之后这个改观了很多 ...

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

    做项目过程中肯定会碰到这样一个问题:在数据库中存的是date或datetime类型的值,从数据库里取出来遍历到页面上显示的是long类型或是GTM类型的日期时间. 对于这个问题,经过研究之后有以下结论 ...

  7. 设置eclipse中的编辑区的背景颜色、注释文字的颜色、修改注释内作者名和时间

    1.编辑区的背景颜色修改按以下步骤: window-->preferences-->general-->Editors-->Text Editors   然后在appearan ...

  8. momentJs 字符串日期时间转换成date

    由于要给elementui 赋值date类型 百度了好几个答案都是错误 就在官网找了下直接toDate()就可以了 时间类型 2021-08-01 14:06:26 let sja = moment( ...

  9. idea里注释日期怎么_IntelliJ IDEA自动注释作者信息和日期时间

    风格1:简约Style 效果如下: 设置步骤: File--> Settings--> Editor--> File and Code Templates--> Include ...

最新文章

  1. 基于Hadoop的大数据平台实施记——整体架构设计[转]
  2. visual studio 2017 添加自定义代码片段 .snippet文件
  3. Linux bond6配置文件,Linux服务器网卡绑定bond配置(示例代码)
  4. 在Ubuntu上编译libusb
  5. eventsource前台怎么接收一个对象数据_Java开发经验总结篇(1)——数据保存的整洁方法...
  6. UVA1584 UVALive3225 Circular Sequence【水题】
  7. MySQL 性能优化的19个要点
  8. 网络流 增广路 入门很好的文章
  9. python怎么设置notebook_JupyterNotebook设置Python环境的方法步骤
  10. rtl8821cs wifi驱动调试 imx6
  11. 5G+MEC+V2X车联网解决方案白皮书
  12. 微信到 Obsidian 2.0
  13. java设置word图片居中_Word中怎样快速对齐图片?这样操作,效率提升10倍
  14. 主机ping虚拟机 TTL传输中过期的解决办法
  15. Matlab统计图片中不同颜色小球个数
  16. 【组成原理-处理器】微程序控制器
  17. 【C语言】sizeof操作符详解
  18. 热烈祝贺!蓝海创意云&姚建萍刺绣艺术虚拟直播合作圆满成功!
  19. char字符对应的ASCII码值
  20. 三轴陀螺仪 偏置稳定性 光纤陀螺 光纤陀螺仪 光纤陀螺惯性导航系统 光纤陀螺惯性测量单元 六自由度IMU 单轴激光陀螺仪 双天线组合导航系统 双轴精确陀螺仪 导航级FOG怎么选择?

热门文章

  1. 解决Win10 VirtualBox无法启动(VERR_NEM_VM_CREATE_FAILED)
  2. 计算机考研基础必考知识点,2020考研计算机数学49个基础知识点
  3. 一切未晚——七公主后花园的成立
  4. AppleTV的设置
  5. nyoj 144 小珂的烦恼
  6. jQuery 图像 360 度旋转插件
  7. pjsip 屏幕直播
  8. 关于Surface键盘突然失灵的解决方案
  9. 思科 | VLAN 间路由实验(三层交换机)
  10. java研究所APP打开_Java是什么,学了我们能干什么?