Eclipse Date and time format customization

Source: Internet
Author: User
Tags dateformat

Click the download Eclipse plugin Org.eclipse.text_3.5.300.v20130515-1451.jar to overwrite the jar file shown.

/******************************************************************************* * Copyright (c), 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * is made available under the terms of the Eclipse public License v1.0 * whic H accompanies this distribution, and are available at *http://www.eclipse.org/legal/epl-v10.html* * Contributors: * IBM corporation-initial API and implementation * Sebastian Davids: [Email protected]- See Bug 25376 *******************************************************************************/ Packageorg.eclipse.jface.text.templates;ImportJava.text.SimpleDateFormat;ImportCom.ibm.icu.text.DateFormat;ImportCom.ibm.icu.util.Calendar;/*** Global variables which is available in no context. * <p> * Clients may instantiate the classes contained WI Thin this class. * </p> * *@since3.0*/ Public classGlobaltemplatevariables {/**The type of the selection variables.*/     Public Static FinalString selection= "SELECTION";//$NON-nls-1$    /*** The cursor variable determines the cursor placement after template edition. */     Public Static classCursorextendsSimpletemplatevariableresolver {/**Name of the cursor variable, value= {@value} */         Public Static FinalString name= "cursor";//$NON-nls-1$        /*** Creates a new cursor variable*/         PublicCursor () {Super(NAME, Texttemplatemessages.getstring ("GlobalVariables.variable.description.cursor"));//$NON-nls-1$Setevaluationstring ("");//$NON-nls-1$        }    }    /*** The word selection variable determines templates that work in a full * lines selection. */     Public Static classWordselectionextendsSimpletemplatevariableresolver {/**Name of the word selection variable, value= {@value} */         Public Static FinalString name= "Word_selection";//$NON-nls-1$        /*** Creates a new word selection variable*/         Publicwordselection () {Super(NAME, Texttemplatemessages.getstring ("GlobalVariables.variable.description.selectedWord"));//$NON-nls-1$        }        protectedString Resolve (Templatecontext context) {string Selection=context.getvariable (SELECTION); if(Selection = =NULL)                return"";//$NON-nls-1$            returnselection; }    }    /*** The line selection variable determines templates this work on selected * lines. */     Public Static classLineselectionextendsSimpletemplatevariableresolver {/**Name of the line selection variable, value= {@value} */         Public Static FinalString name= "Line_selection";//$NON-nls-1$        /*** Creates a new line selection variable*/         Publiclineselection () {Super(NAME, Texttemplatemessages.getstring ("GlobalVariables.variable.description.selectedLines"));//$NON-nls-1$        }        protectedString Resolve (Templatecontext context) {string Selection=context.getvariable (SELECTION); if(Selection = =NULL)                return"";//$NON-nls-1$            returnselection; }    }    /*** The dollar variable inserts an escaped dollar symbol. */     Public Static classDollarextendsSimpletemplatevariableresolver {/*** Creates a new dollar variable*/         PublicDollar () {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 classDateextendsSimpletemplatevariableresolver {/*** Creates a new date variable*/         PublicDate () {Super("Date", Texttemplatemessages.getstring ("GlobalVariables.variable.description.date"));//$NON-nls-1$//$NON-nls-2$        }        protectedString Resolve (Templatecontext context) {//return Dateformat.getdateinstance (). Format (new java.util.Date ());             final simpledateformat df = new simpledateformat ("Yyyy-mm-dd"); returnDf.format (Newjava.util.Date ()); }    }    /*** The year variable evaluates to the current year . */     Public Static classYearextendsSimpletemplatevariableresolver {/*** Creates a New Year variable*/         PublicYear () {Super("Year", Texttemplatemessages.getstring ("GlobalVariables.variable.description.year"));//$NON-nls-1$//$NON-nls-2$        }        protectedString Resolve (Templatecontext context) {returninteger.tostring (Calendar.getinstance (). Get (Calendar.year)); }    }    /*** The time variable evaluates to the current time . */     Public Static classTimeextendsSimpletemplatevariableresolver {/*** Creates a new time variable*/         PublicTime () {Super("Time", Texttemplatemessages.getstring ("GlobalVariables.variable.description.time"));//$NON-nls-1$//$NON-nls-2$        }        /**         * {@inheritDoc}         */        protectedString Resolve (Templatecontext context) {//return Dateformat.gettimeinstance (). Format (new java.util.Date ());             final simpledateformat df = new simpledateformat ("hh:mm"); returnDf.format (Newjava.util.Date ()); }    }    /*** The user variable evaluates to the current user. */     Public Static classUserextendsSimpletemplatevariableresolver {/*** Creates a new user name variable*/         PublicUser () {Super("User", Texttemplatemessages.getstring ("GlobalVariables.variable.description.user"));//$NON-nls-1$//$NON-nls-2$        }        /**         * {@inheritDoc}         */        protectedString Resolve (Templatecontext context) {returnSystem.getproperty ("User.Name");//$NON-nls-1$        }    }}

Eclipse Date and time format customization

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.