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包的版本号问题)

/*******************************************************************************
* 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. 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. GreenDao数据库结构升级

    1.先用GreenDao工具类编写自动创建代码,按照升级后的最新数据库结构来编写 2.GreenDao工具自动生成的代码覆盖到项目里去 3.在项目里找到对应的自动生成的数据库DaoMaster类 在D ...

  2. Eclipse和PyDev搭建完美Python开发环境(Windows篇)(转)

      摘要:本文讲解了用Eclipse和PyDev搭建Python的开发环境. 十一长假在家闲着没事儿,准备花点时间学习一下Python. 今儿花了一个下午搭建Python的开发环境,不禁感叹————开 ...

  3. 手机端viewport的设置规范

    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale ...

  4. 进阶:案例三: Upload File using WebDynpro

    1.节点创建,其中DATASOURCE存放uploadfile名称 2.layout布局 3.upload事件代码: method ONACTIONUPLOAD . DATA: lo_Node typ ...

  5. 模拟产生CBC LATCH与buffer busy wait等待事件

    数据库版本:11.2.0.4.0 1.查出表TEST相关信息 select rowid, dbms_rowid.rowid_row_number(rowid) rowid_rownum, dbms_r ...

  6. Uva - 11383 - Golden Tiger Claw

    题意:一个N*N的矩阵,第i行第j列的元素大小为w[i][j],每行求一个数row[i],每列求一个数col[j],使得row[i] + col[j] >= w[i][j],且所有的row[]与 ...

  7. Excel单元格内容太多会覆盖遮住下一单元格范围

    Excel单元格内容太多会覆盖遮住下一单元格范围分步阅读 Excel中的单元格内容,有着不同的对齐方式.用户可根据自己的需求,在处理数据的时候,自行设置所需要的对齐方式. 当您在处理数据的时候,如果设 ...

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

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

  9. Redis核心解读:集群管理工具(Redis-sentinel)

    Redis核心解读:集群管理工具(Redis-sentinel) - Redis - TechTarget数据库 Redis核心解读:集群管理工具(Redis-sentinel)

  10. Jsoup API解析HTML中input标签

    Jsoup官网地址:http://jsoup.org/ 1. 解析单个input元素     String html = "<p><input align=\"t ...