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:假设嫌下载源代码包麻烦。我这里贴出这个文件的源代码,能够直接用(注:这个类非常easy。无多少依赖。全部版本号通用,无需操心jar包的版本号问题)

  1. /*******************************************************************************
  2. * Copyright (c) 2000, 2006 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * IBM Corporation - initial API and implementation
  10. * Sebastian Davids: sdavids@gmx.de - see bug 25376
  11. *******************************************************************************/
  12. package org.eclipse.jface.text.templates;
  13.  
  14. import com.ibm.icu.text.DateFormat;
  15. import com.ibm.icu.util.Calendar;
  16.  
  17. /**
  18. * Global variables which are available in any context.
  19. * <p>
  20. * Clients may instantiate the classes contained within this class.
  21. * </p>
  22. *
  23. * @since 3.0
  24. */
  25. public class GlobalTemplateVariables {
  26.  
  27. /** The type of the selection variables. */
  28. public static final String SELECTION= "selection"; //$NON-NLS-1$
  29.  
  30. /**
  31. * The cursor variable determines the cursor placement after template edition.
  32. */
  33. public static class Cursor extends SimpleTemplateVariableResolver {
  34.  
  35. /** Name of the cursor variable, value= {@value} */
  36. public static final String NAME= "cursor"; //$NON-NLS-1$
  37.  
  38. /**
  39. * Creates a new cursor variable
  40. */
  41. public Cursor() {
  42. super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$
  43. setEvaluationString(""); //$NON-NLS-1$
  44. }
  45. }
  46.  
  47. /**
  48. * The word selection variable determines templates that work on a full
  49. * lines selection.
  50. */
  51. public static class WordSelection extends SimpleTemplateVariableResolver {
  52.  
  53. /** Name of the word selection variable, value= {@value} */
  54. public static final String NAME= "word_selection"; //$NON-NLS-1$
  55.  
  56. /**
  57. * Creates a new word selection variable
  58. */
  59. public WordSelection() {
  60. super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedWord")); //$NON-NLS-1$
  61. }
  62. protected String resolve(TemplateContext context) {
  63. String selection= context.getVariable(SELECTION);
  64. if (selection == null)
  65. return ""; //$NON-NLS-1$
  66. return selection;
  67. }
  68. }
  69.  
  70. /**
  71. * The line selection variable determines templates that work on selected
  72. * lines.
  73. */
  74. public static class LineSelection extends SimpleTemplateVariableResolver {
  75.  
  76. /** Name of the line selection variable, value= {@value} */
  77. public static final String NAME= "line_selection"; //$NON-NLS-1$
  78.  
  79. /**
  80. * Creates a new line selection variable
  81. */
  82. public LineSelection() {
  83. super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedLines")); //$NON-NLS-1$
  84. }
  85. protected String resolve(TemplateContext context) {
  86. String selection= context.getVariable(SELECTION);
  87. if (selection == null)
  88. return ""; //$NON-NLS-1$
  89. return selection;
  90. }
  91. }
  92.  
  93. /**
  94. * The dollar variable inserts an escaped dollar symbol.
  95. */
  96. public static class Dollar extends SimpleTemplateVariableResolver {
  97. /**
  98. * Creates a new dollar variable
  99. */
  100. public Dollar() {
  101. super("dollar", TextTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$
  102. setEvaluationString("$"); //$NON-NLS-1$
  103. }
  104. }
  105.  
  106. /**
  107. * The date variable evaluates to the current date.
  108. */
  109. public static class Date extends SimpleTemplateVariableResolver {
  110. /**
  111. * Creates a new date variable
  112. */
  113. public Date() {
  114. super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
  115. }
  116. protected String resolve(TemplateContext context) {
  117. return DateFormat.getDateInstance().format(new java.util.Date());
  118. }
  119. }
  120.  
  121. /**
  122. * The year variable evaluates to the current year.
  123. */
  124. public static class Year extends SimpleTemplateVariableResolver {
  125. /**
  126. * Creates a new year variable
  127. */
  128. public Year() {
  129. super("year", TextTemplateMessages.getString("GlobalVariables.variable.description.year")); //$NON-NLS-1$ //$NON-NLS-2$
  130. }
  131. protected String resolve(TemplateContext context) {
  132. return Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
  133. }
  134. }
  135.  
  136. /**
  137. * The time variable evaluates to the current time.
  138. */
  139. public static class Time extends SimpleTemplateVariableResolver {
  140. /**
  141. * Creates a new time variable
  142. */
  143. public Time() {
  144. super("time", TextTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$
  145. }
  146.  
  147. /**
  148. * {@inheritDoc}
  149. */
  150. protected String resolve(TemplateContext context) {
  151. return DateFormat.getTimeInstance().format(new java.util.Date());
  152. }
  153. }
  154.  
  155. /**
  156. * The user variable evaluates to the current user.
  157. */
  158. public static class User extends SimpleTemplateVariableResolver {
  159. /**
  160. * Creates a new user name variable
  161. */
  162. public User() {
  163. super("user", TextTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$
  164. }
  165.  
  166. /**
  167. * {@inheritDoc}
  168. */
  169. protected String resolve(TemplateContext context) {
  170. return System.getProperty("user.name"); //$NON-NLS-1$
  171. }
  172. }
  173. }

自行拿去改动即可了。改一下Date Time Year即可了,比如。我改动的结果例如以下:

  1. /*******************************************************************************
  2. * Copyright (c) 2000, 2006 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * IBM Corporation - initial API and implementation
  10. * Sebastian Davids: sdavids@gmx.de - see bug 25376
  11. *******************************************************************************/
  12. package org.eclipse.jface.text.templates;
  13.  
  14. import java.text.SimpleDateFormat;
  15. import java.util.Calendar;
  16.  
  17. /**
  18. * Global variables which are available in any context.
  19. * <p>
  20. * Clients may instantiate the classes contained within this class.
  21. * </p>
  22. *
  23. * @since 3.0
  24. */
  25. public class GlobalTemplateVariables {
  26.  
  27. /** The type of the selection variables. */
  28. public static final String SELECTION= "selection"; //$NON-NLS-1$
  29.  
  30. /**
  31. * The cursor variable determines the cursor placement after template edition.
  32. */
  33. public static class Cursor extends SimpleTemplateVariableResolver {
  34.  
  35. /** Name of the cursor variable, value= {@value} */
  36. public static final String NAME= "cursor"; //$NON-NLS-1$
  37.  
  38. /**
  39. * Creates a new cursor variable
  40. */
  41. public Cursor() {
  42. super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$
  43. setEvaluationString(""); //$NON-NLS-1$
  44. }
  45. }
  46.  
  47. /**
  48. * The word selection variable determines templates that work on a full
  49. * lines selection.
  50. */
  51. public static class WordSelection extends SimpleTemplateVariableResolver {
  52.  
  53. /** Name of the word selection variable, value= {@value} */
  54. public static final String NAME= "word_selection"; //$NON-NLS-1$
  55.  
  56. /**
  57. * Creates a new word selection variable
  58. */
  59. public WordSelection() {
  60. super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedWord")); //$NON-NLS-1$
  61. }
  62. protected String resolve(TemplateContext context) {
  63. String selection= context.getVariable(SELECTION);
  64. if (selection == null)
  65. return ""; //$NON-NLS-1$
  66. return selection;
  67. }
  68. }
  69.  
  70. /**
  71. * The line selection variable determines templates that work on selected
  72. * lines.
  73. */
  74. public static class LineSelection extends SimpleTemplateVariableResolver {
  75.  
  76. /** Name of the line selection variable, value= {@value} */
  77. public static final String NAME= "line_selection"; //$NON-NLS-1$
  78.  
  79. /**
  80. * Creates a new line selection variable
  81. */
  82. public LineSelection() {
  83. super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedLines")); //$NON-NLS-1$
  84. }
  85. protected String resolve(TemplateContext context) {
  86. String selection= context.getVariable(SELECTION);
  87. if (selection == null)
  88. return ""; //$NON-NLS-1$
  89. return selection;
  90. }
  91. }
  92.  
  93. /**
  94. * The dollar variable inserts an escaped dollar symbol.
  95. */
  96. public static class Dollar extends SimpleTemplateVariableResolver {
  97. /**
  98. * Creates a new dollar variable
  99. */
  100. public Dollar() {
  101. super("dollar", TextTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$
  102. setEvaluationString("$"); //$NON-NLS-1$
  103. }
  104. }
  105.  
  106. /**
  107. * The date variable evaluates to the current date.
  108. */
  109. public static class Date extends SimpleTemplateVariableResolver {
  110. /**
  111. * Creates a new date variable
  112. */
  113. public Date() {
  114. super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
  115. }
  116. protected String resolve(TemplateContext context) {
  117. // return DateFormat.getDateInstance().format(new java.util.Date());
  118. final SimpleDateFormat df = new SimpleDateFormat(TextTemplateMessages.getString("GlobalVariables.variable.format.date"));
  119. return df.format(new java.util.Date());
  120. }
  121. }
  122.  
  123. /**
  124. * The year variable evaluates to the current year.
  125. */
  126. public static class Year extends SimpleTemplateVariableResolver {
  127. /**
  128. * Creates a new year variable
  129. */
  130. public Year() {
  131. super("year", TextTemplateMessages.getString("GlobalVariables.variable.description.year")); //$NON-NLS-1$ //$NON-NLS-2$
  132. }
  133. protected String resolve(TemplateContext context) {
  134. // return Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
  135. return Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
  136. }
  137. }
  138.  
  139. /**
  140. * The time variable evaluates to the current time.
  141. */
  142. public static class Time extends SimpleTemplateVariableResolver {
  143. /**
  144. * Creates a new time variable
  145. */
  146. public Time() {
  147. super("time", TextTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$
  148. }
  149.  
  150. /**
  151. * {@inheritDoc}
  152. */
  153. protected String resolve(TemplateContext context) {
  154. final SimpleDateFormat df = new SimpleDateFormat(TextTemplateMessages.getString("GlobalVariables.variable.format.time"));
  155. return df.format(new java.util.Date());
  156. //return DateFormat.getTimeInstance().format(new java.util.Date());
  157. }
  158. }
  159.  
  160. /**
  161. * The user variable evaluates to the current user.
  162. */
  163. public static class User extends SimpleTemplateVariableResolver {
  164. /**
  165. * Creates a new user name variable
  166. */
  167. public User() {
  168. super("user", TextTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$
  169. }
  170.  
  171. /**
  172. * {@inheritDoc}
  173. */
  174. protected String resolve(TemplateContext context) {
  175. return System.getProperty("user.name"); //$NON-NLS-1$
  176. }
  177. }
  178. }

我改成了使用

import java.text.SimpleDateFormat;

import java.util.Calendar;

而且从properties文件里读取format格式,能够借鉴。

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

Eclipse 改动凝视的 date time 日期时间格式,即${date}变量格式的更多相关文章

  1. Java魔法堂:Date与日期时间格式化

    一.前言                                                                                       日期时间的获取.显 ...

  2. 日期时间类:Date,Calendar,计算类:Math

    日期时间类 计算机如何表示时间? 时间戳(timestamp):距离特定时间的时间间隔. 计算机时间戳是指距离历元(1970-01-01 00:00:00:000)的时间间隔(ms). 计算机中时间2 ...

  3. Perl 日期时间函数(date time)

    use Time::HiRes qw(time);use POSIX qw(strftime); my $t = time;my $date = strftime "%Y%m%d %H:%M ...

  4. java8中计算两个日期时间LocalDateTime的时间差,格式化成xx年yy月zz日aa时bb分cc秒

    原则上应该适用Period来计算,因为他是专门为这种需求设计的.当时他只能计算到两个时间差的,年月日 传入参数Period.between(LocalDate,LocalDate) 这里是计算两个Lo ...

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

    原文地址:http://www.cnblogs.com/diyunpeng/archive/2011/11/20/2256538.html 用途说明 ate命令可以用来显示和修改系统日期时间,注意不是 ...

  6. 【Linux基础】Linux命令date 日期时间

    1.显示到纳秒 date +%F.%H:%M:%S.%N --:38.740127086 date +%Y-%m-%d.%H:%M:%S.%N2019-04-25.00:28:24.060756673 ...

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

    用途说明 ate命令可以用来显示和修改系统日期时间,注意不是time命令. 常用参数 格式:date 显示当前日期时间. 格式:date mmddHHMM 格式:date mmddHHMMYYYY 格 ...

  8. JavaScript中的内置对象-8--4.date对象中-获取,设置日期时间的方法; 获取,设置年月日时分秒及星期的方法;

    学习目标 1.掌握创建日期对象的方法 2.掌握date对象中获取日期时间的方法 3.掌握date对象中设置日期时间的方法 如何创建一个日期对象 语法:new Date(); 功能:创建一个日期时间对象 ...

  9. [转]JDBC中日期时间的处理技巧

    Java中用类java.util.Date对日期/时间做了封装,此类提供了对年.月.日.时.分.秒.毫秒以及时区的控制方法,同时也提供一些工具方法,比如日期/时间的比较,前后判断等. java.uti ...

随机推荐

  1. 细节!重点!易错点!--面试java基础篇(一)

    今天来给大家分享一下java的重点易错点部分,也是各位同学面试需要准备的,欢迎大家交流指正. 1.java中的main方法是静态方法,即方法中的代码是存储在静态存储区的. 2.任何静态代码块都会在ma ...

  2. Qt之开机自启动及拥有管理员权限

    源地址:http://blog.sina.cn/dpool/blog/s/blog_a6fb6cc90101feia.html Windows开机自启动的程序很多,包括系统软件.杀毒软件.一些其他安装 ...

  3. uva 10692 - Huge Mods(数论)

    题目链接:uva 10692 - Huge Mods 题目大意:给出一个数的次方形式,就它模掉M的值. 解题思路:依据剩余系的性质,最后一定是行成周期的,所以就有ab=abmod(phi[M])+ph ...

  4. readline-6.3 之arm平台交叉编译

    近期须要弄个CLI命令接口程序,初步设想是须要支持历史命令翻阅,tab键命令补全这种一个东西.经查阅相关文档,深耕百度一番!(google近期不太正常) 实在恼火.发现readline果真是个好东西, ...

  5. 发掘ListBox的潜力(二):鼠标拖放插入点提示

    鼠标拖放插入点提示 鼠标拖放是Windows常见的操作,比如拷贝文件就可用拖放方式进行.在我们编写的应用程序中,有时为了方便用户操作需要支持鼠标拖放.对于大部分的VCL控件只要鼠标将DragMode设 ...

  6. Android Sip学习(三)Android Voip实现

    Android Sip学习(三)Android Voip实现   Android Sip学习(准备知识)SIP 协议完整的呼叫流程 Android Sip学习(一)Android 2.3 APIs S ...

  7. VS2010 编译安装boost库

    实践是最好的办法..学习C++,想试试线程,然后打算用boost库,结果boost库编译差点吓到我..没看到比较完整的安装教程..一直耽搁.今天动手.完成了.方法记录如下:1.下载boost从boos ...

  8. SetFocus、SetCapture和SetActiveView的区别

    1. SetActiveView是MFC框架内的一个函数, 而不是SDK中的函数, 也就是说SDK中没有ActiveView这个概念, 只有在MFC中才有2. SetFocus是SDK中的函数(当然M ...

  9. C++(MFC)中WebBrowser去除3D边框的方法(实现IDocHostUIHandler接口)

    先说实在的:最终解决办法是实现IDocHostUIHandler接口,在GetHostInfo方法里解决,但“实现接口”意味着QueryInterface.AddRef.Release三个方法必须实现 ...

  10. [读书笔记]黑客与画家[Hackers.and.Painters]

    (书生注:这本书写的不错.针对程序员,可以带来不同角度的想法,有助于反思自己的程序员工作.我甚至从中发现了自己爱用铅笔的原因...  尤其是其中关于黑客的定义,包括黑客认为的乐趣和目的,让人更深层次思 ...