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:假设嫌下载源代码包麻烦。我这里贴出这个文件的源代码,能够直接用(注:这个类非常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}变量格式的更多相关文章
- Java魔法堂:Date与日期时间格式化
一.前言 日期时间的获取.显 ...
- 日期时间类:Date,Calendar,计算类:Math
日期时间类 计算机如何表示时间? 时间戳(timestamp):距离特定时间的时间间隔. 计算机时间戳是指距离历元(1970-01-01 00:00:00:000)的时间间隔(ms). 计算机中时间2 ...
- Perl 日期时间函数(date time)
use Time::HiRes qw(time);use POSIX qw(strftime); my $t = time;my $date = strftime "%Y%m%d %H:%M ...
- java8中计算两个日期时间LocalDateTime的时间差,格式化成xx年yy月zz日aa时bb分cc秒
原则上应该适用Period来计算,因为他是专门为这种需求设计的.当时他只能计算到两个时间差的,年月日 传入参数Period.between(LocalDate,LocalDate) 这里是计算两个Lo ...
- 我使用过的Linux命令之date - 显示、修改系统日期时间
原文地址:http://www.cnblogs.com/diyunpeng/archive/2011/11/20/2256538.html 用途说明 ate命令可以用来显示和修改系统日期时间,注意不是 ...
- 【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 ...
- 我使用过的Linux命令之date - 显示、修改系统日期时间(转)
用途说明 ate命令可以用来显示和修改系统日期时间,注意不是time命令. 常用参数 格式:date 显示当前日期时间. 格式:date mmddHHMM 格式:date mmddHHMMYYYY 格 ...
- JavaScript中的内置对象-8--4.date对象中-获取,设置日期时间的方法; 获取,设置年月日时分秒及星期的方法;
学习目标 1.掌握创建日期对象的方法 2.掌握date对象中获取日期时间的方法 3.掌握date对象中设置日期时间的方法 如何创建一个日期对象 语法:new Date(); 功能:创建一个日期时间对象 ...
- [转]JDBC中日期时间的处理技巧
Java中用类java.util.Date对日期/时间做了封装,此类提供了对年.月.日.时.分.秒.毫秒以及时区的控制方法,同时也提供一些工具方法,比如日期/时间的比较,前后判断等. java.uti ...
随机推荐
- Win2003 Server磁盘配额揭密之启用篇
Win2003 Server磁盘配额揭密之启用篇 [ 作者:茶乡浪子 转贴自:it168.com 点击数:4973 更新时间:2005-1-17 ] 本文要向大家介绍如何利用W ...
- QString ini ;转义符
ini如果value字符串中存在:,通过双引号即可转义 [a] b=sdc";"gf
- Google App Engine 学习和实践
这个周末玩了玩Google App Engine,随手写点东西,算是学习笔记吧.不当之处,请多多指正. 作者:liigo,2009/04/26夜,大连 原创链接:http://blog.csdn.ne ...
- 【OpenCV】漫水填充
漫水填充:也就是用一定颜色填充联通区域,通过设置可连通像素的上下限以及连通方式来达到不同的填充效果;漫水填充经常被用来标记或分离图像的一部分以便对其进行进一步处理或分析,也可以用来从输入图像获取掩码区 ...
- Swift - 多线程实现方式(1) - NSThread
1,Swift继续使用Object-C原有的一套线程,包括三种多线程编程技术: (1)NSThread (2)Cocoa NSOperation(NSOperation和NSOperationQueu ...
- 让Delphi XE2程序支持UAC
在win7下,开发的程序有的时候莫名其妙就不能正常工作了,其实都是因为权限不够,要想能够正常运行,就需要获得管理员权限,这就需要处理UAC.具体方法如下: 一,制作“uac.manifest”文件.新 ...
- delphi不同版本字符串类型的演化(要支持基于firemonkey的app调用,字符串最好使用olevariant类型)
string,DELPHI2009以前的版本string=ansistring,一个字符占一个字节,DELPHI2009及以上版本string=unicodestring,一个字符占二个字节. cha ...
- 【Demo 0009】Java基础-异常
本章学习要点: 1. 了解异常的基本概念: 2. 掌握异常捕获方法以及注意事项; 3. 掌握异常抛出方法: 4. 掌握自定义异常类和异常类继承注 ...
- BestR #31
hdu 5178 求|a[i] - a[j]| <= k (i < j) <i,j>的对数,一开始认为数据不大就直接ans++了,后来结果出来才知道,啊啊啊,too young ...
- JavaScript快速入门(六)——DOM
概念扫盲 DOM DOM是 Document Object Model(文档对象模型)的缩写,是W3C(万维网联盟)的标准.DOM 定义了访问 HTML 和 XML 文档的标准:“W3C 文档对象模型 ...