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 ...
随机推荐
- 细节!重点!易错点!--面试java基础篇(一)
今天来给大家分享一下java的重点易错点部分,也是各位同学面试需要准备的,欢迎大家交流指正. 1.java中的main方法是静态方法,即方法中的代码是存储在静态存储区的. 2.任何静态代码块都会在ma ...
- Qt之开机自启动及拥有管理员权限
源地址:http://blog.sina.cn/dpool/blog/s/blog_a6fb6cc90101feia.html Windows开机自启动的程序很多,包括系统软件.杀毒软件.一些其他安装 ...
- uva 10692 - Huge Mods(数论)
题目链接:uva 10692 - Huge Mods 题目大意:给出一个数的次方形式,就它模掉M的值. 解题思路:依据剩余系的性质,最后一定是行成周期的,所以就有ab=abmod(phi[M])+ph ...
- readline-6.3 之arm平台交叉编译
近期须要弄个CLI命令接口程序,初步设想是须要支持历史命令翻阅,tab键命令补全这种一个东西.经查阅相关文档,深耕百度一番!(google近期不太正常) 实在恼火.发现readline果真是个好东西, ...
- 发掘ListBox的潜力(二):鼠标拖放插入点提示
鼠标拖放插入点提示 鼠标拖放是Windows常见的操作,比如拷贝文件就可用拖放方式进行.在我们编写的应用程序中,有时为了方便用户操作需要支持鼠标拖放.对于大部分的VCL控件只要鼠标将DragMode设 ...
- Android Sip学习(三)Android Voip实现
Android Sip学习(三)Android Voip实现 Android Sip学习(准备知识)SIP 协议完整的呼叫流程 Android Sip学习(一)Android 2.3 APIs S ...
- VS2010 编译安装boost库
实践是最好的办法..学习C++,想试试线程,然后打算用boost库,结果boost库编译差点吓到我..没看到比较完整的安装教程..一直耽搁.今天动手.完成了.方法记录如下:1.下载boost从boos ...
- SetFocus、SetCapture和SetActiveView的区别
1. SetActiveView是MFC框架内的一个函数, 而不是SDK中的函数, 也就是说SDK中没有ActiveView这个概念, 只有在MFC中才有2. SetFocus是SDK中的函数(当然M ...
- C++(MFC)中WebBrowser去除3D边框的方法(实现IDocHostUIHandler接口)
先说实在的:最终解决办法是实现IDocHostUIHandler接口,在GetHostInfo方法里解决,但“实现接口”意味着QueryInterface.AddRef.Release三个方法必须实现 ...
- [读书笔记]黑客与画家[Hackers.and.Painters]
(书生注:这本书写的不错.针对程序员,可以带来不同角度的想法,有助于反思自己的程序员工作.我甚至从中发现了自己爱用铅笔的原因... 尤其是其中关于黑客的定义,包括黑客认为的乐趣和目的,让人更深层次思 ...