Java Code Examples for javax.swing.text.DateFormatter

Following code examples demonstrate how to use javax.swing.text.DateFormatterfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use javax.swing.text.DateFormatterand various code implementation of this class.

	public void printDate(){
		ThreadLocal<DateFormatter> thread = ThreadLocal.withInitial( 
				() -> new DateFormatter(
						new SimpleDateFormat("dd-MMM-YYYY")
					)	
				);
		
		System.out.println(thread.get().getFormat().format(new Date()));
	} 


	public void printDateFormatter() {
		try {
			System.out.println(threadSafeDateFormatter.get().toString() + ": " + threadSafeDateFormatter.get().valueToString(new Date()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
	} 

	public static void main(String... args) {
		DateFormatter df = tldf.get();
		System.out.println(df
				.getFormat()
				.format(new Date()));
	} 

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to DateFormatter.class!",
                   DateFormatter.class.isAssignableFrom(sut));
    } 

    @Category(Draft.class)
    public void create_DateFormatter()
    throws Exception {
        @SuppressWarnings("unused")
        final DateFormatter sut = new DateFormatter();
    } 

Advertisement
Javadoc
DateFormatter is an InternationalFormatter that does its formatting by way of an instance of java.te

xt.DateFormat.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans™ has been added to the java.beans package. Please see java.beans.XMLEncoder. @see java.text.DateFormat @since 1.4

Read More
Advertisement