Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the Eclipse date variable format?

How can I set the format for the ${date} variable which can be used in Eclipse templates?

like image 709
desolat Avatar asked Jul 15 '09 14:07

desolat


People also ask

How do you format a date in Java?

Java SimpleDateFormat with Locale String pattern = "EEEEE MMMMM yyyy HH:mm:ss. SSSZ"; SimpleDateFormat simpleDateFormat =new SimpleDateFormat(pattern, new Locale("fr", "FR")); String date = simpleDateFormat. format(new Date()); System.

What is the default format of DateTime?

uses a default date format to store and manipulate strings that represent dates. To specify the default date format, enter a date format in the DateTime Format String attribute in the data viewer configuration. By default, the date format is MM/DD/YYYY HH24:MI:SS.US.

What is the default date format in C#?

DateTimeFormat. ShortDatePattern = "dd-MMM-yyyy"; culture. DateTimeFormat.


2 Answers

Update February 2016: bug 75981 is officially fixed!
See Jmini's answer below

enter image description here


Update July 2015, 6 years later:

The bug mentioned below seems fixed in Eclipse 4.x.
Eric Wang comments below:

@date ${id:date('YYYY-MMM-dd')} ${time}  

this give me English datetime format in eclipse 4.


Original Answer 2009 Eclipse 3.x

Argh! There is a long standing bug just for that: bug 75981

The ${date} variable could be enhanced to accept an argument (similar to other parameterizations added in 3.3M1), e.g. ${d:date(format)}, where format is a pattern for SimpleDateFormat.

The only alternative would be to modify the class SimpleTemplateVariableResolver (as described in this thread), from the package org.eclipse.jface.text.templates. (You have here an example of such an extension).

This thread mentions the sources where you can find the class.

\eclipse\plugins\org.eclipse.platform.source_3.1.0\src\org.eclipse.text_3.1.0\src.zip 

Example:

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());     DateFormat df = new SimpleDateFormat("dd/MM/yyyy");     return df.format(new java.util.Date()); } } 
like image 199
VonC Avatar answered Sep 18 '22 14:09

VonC


You could tell Eclipse to use a specific locale different from that of your operating system. Eclipse 3.5 (64 bit) doesn't use the MacOS X region setting. MacOS X english installation language with Germany as country provides a wrong date format.

You can fix it for your Eclipse installation when you append following lines to your eclipse.ini:

-Duser.language=de -Duser.region=DE 
like image 26
jAgile Avatar answered Sep 20 '22 14:09

jAgile