Eclipse 日期和时间格式自定义
2018-2-6 16:53:13 更新 Eclipse 4.7.2(下载后.zip改为.jar): org.eclipse.text_3.6.100.v20170203-0814.jar
点击下载Eclipse插件 org.eclipse.text_3.5.300.v20130515-1451.jar 覆盖下图所示的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 java.text.SimpleDateFormat; 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());
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
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));
}
} /**
* 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());
final SimpleDateFormat df = new SimpleDateFormat("HH:mm");
return df.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$
}
}
}
Eclipse 日期和时间格式自定义的更多相关文章
- 不修改系统日期和时间格式,解决Delphi报错提示 '****-**-**'is not a valid date and time
假如操作系统的日期格式不是yyyy-MM-dd格式,而是用strtodate('2014-10-01')) 来转换的话,程序会提示爆粗 '****-**-**'is not a valid date ...
- style不同取值对应的日期、时间格式
from : http://www.cnblogs.com/Gavinzhao/archive/2009/11/10/1599690.html sql server2000中使用convert来取得d ...
- Java 8新增的日期、时间格式器
一 获取DateTimeFormatter对象的三种方式 直接使用静态常量创建DateTimeFormatter格式器 使用代码不同风格的枚举值来创建DateTimeFormatter格式器 根据模式 ...
- 如何修改Django中的日期和时间格式 DateTimeField
html页面从数据库中读出DateTimeField字段时,显示的时间格式和数据库中存放的格式不一致,比如数据库字段内容为2017-06-03 13:00:00,但是页面显示的却是Apr. 03, 2 ...
- Django中的日期和时间格式 DateTimeField
创建django的model时,有DateTimeField.DateField和TimeField三种类型可以用来创建日期字段,其值分别对应着datetime().date().time()三中对象 ...
- obj 转为Json 时间格式自定义
var tb = evnWarningBll.GatWarning(); var timeFormat = new IsoDateTimeConverter(); ...
- 日期和时间格式(ISO 8601)
参考 ISO 8601 - Wikipedia ISO 8601 Date and time format
- matlab中datest() 将日期和时间转换为字符串格式
来源:https://ww2.mathworks.cn/help/matlab/ref/datestr.html?searchHighlight=datestr&s_tid=doc_srcht ...
- db2 日期时间格式
db2日期和时间常用汇总 1.db2可以通过SYSIBM.SYSDUMMY1.SYSIBM.DUAL获取寄存器中的值,也可以通过VALUES关键字获取寄存器中的值. SELECT 'HELLO DB2 ...
随机推荐
- 基于开源项目SharpMap的热力图(HeatLayer)实现。
当前公司需要一个用时较少的热力图呈现方案,在避免较底层的GDI开发和比较了多家GIS产品的实际效果之后,团队决定用sharpMap的API来实现,由于之前框架采用的是另外一个开源项目GMap.net, ...
- Android(安卓)-------CardView
1.activity_main.xml <android.support.v7.widget.CardView android:id="@+id/cardView" andr ...
- ios 类似微信红点显示功能
设计思路:给UIView增加一个分类 所有的视图都可以根据需要来进行红点显示 #import <UIKit/UIKit.h> @interface UIView (CHRRedDot) @ ...
- 《MySQL必知必会》学习笔记
数据库:数据库是一种以某种有组织的方式存储的数据集合.其本质就是一个容器,通常是一个或者一组文件. 表:表示一种结构化的文件,可用来存储某种特定类型的数据. 模式:描述数据库中特定的表以及整个数据库和 ...
- SQLServer2005创建定时作业任务
SQLServer定时作业任务:即数据库自动按照定时执行的作业任务,具有周期性不需要人工干预的特点 创建步骤:(使用最高权限的账户登录--sa) 一.启动SQL Server代理(SQL Server ...
- Immutable(不可变)集合
不可变集合,顾名思义就是说集合是不可被修改的.集合的数据项是在创建的时候提供,并且在整个生命周期中都不可改变. 为什么要用immutable对象?immutable对象有以下的优点: 对不可靠的客户代 ...
- C# - 缓存OutputCache(二)缓存详细介绍
本文是通过网上&个人总结的 1.缓存介绍 缓存是为了提高访问速度,而做的技术. 缓存主要有以下几类:1)客户端缓存Client Caching 2)代理缓存Proxy Caching 3)方向 ...
- delete
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- C#设计模式-备忘录模式
访问者模式的实现是把作用于某种数据结构上的操作封装到访问者中,使得操作和数据结构隔离.而本文要介绍的备忘者模式与命令模式有点相似,不同的是,命令模式保存的是发起人的具体命令(命令对应的是行为),而备忘 ...
- sublime text添加snippet
下面的${1:this}格式的会在tab键下一次切换选中 <snippet> <content><![CDATA[Hello, ${1:this} is a ${2:sn ...