Wednesday 16 January 2019

How to use formatToCharacterIterator(Object obj) method of java.text.SimpleDateFormat class


Click here to watch on Youtube: 
https://www.youtube.com/watch?v=gXTRW2XP0Wk&list=UUhwKlOVR041tngjerWxVccw

SimpleDateFormatDemo.java

import java.text.CharacterIterator;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleDateFormatDemo
{
    public static void main(String[] args)
    {
        Date date =  new Date();
        System.out.println("date = "+date);
       
        Format formatter = new SimpleDateFormat("MM/dd/yyyy");

        /*
         * Parameters:
         *
         * obj - The object to format
         *
         * Returns:
         *
         * Attributed CharacterIterator describing the formatted
         * value.
         */

        CharacterIterator ci = formatter.formatToCharacterIterator(date);

        for (char ch = ci.first(); ch != CharacterIterator.DONE; ch = ci.next())
        {
            System.out.print(ch);
        }
    }

}

Output:

date = Wed Jan 09 16:04:49 IST 2019
01/09/2019

Click the below link to download the code:
https://sites.google.com/site/javaspringram2019/java_spring_2019/SimpleDateFormatDemo_formatToCharacterIterator.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java_Spring_2019/tree/master/Java_2019/SimpleDateFormatDemo_formatToCharacterIterator

Bitbucket Link:
https://bitbucket.org/ramram43210/java_spring_2019/src/4327965661b34e0cc17880946800be5f5d73f2dd/Java_2019/SimpleDateFormatDemo_formatToCharacterIterator/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Spring Tutorial
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a Comment