Monday 7 January 2019

java.text.DateFormat class Introduction | Dateformatter in java | How to format the date and time


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

Click the below Image to Enlarge:
java.text.DateFormat class Introduction | Dateformatter in java | How to format the date and time

DateFormatDemo.java

import java.text.DateFormat;
import java.util.Date;

public class DateFormatDemo
{
    public static void main(String[] args)
    {
        Date currentDate = new Date();
        System.out.println("Current Date = " + currentDate);

        /*
         * Returns:
         *
         * a default date/time formatter that uses the SHORT style for
         * both the date and the time.
         */

        DateFormat dateFormat = DateFormat.getInstance();
       
        /*
         * Parameters:
         *
         * date - the time value to be formatted into a time string.
         *
         * Returns:
         *
         * the formatted date/time string.
         */

        String dateToStr = dateFormat.format(currentDate);
        System.out.println("Formatted Date = " + dateToStr);
    }
}

Output:

Current Date = Thu Dec 27 08:20:16 IST 2018
Formatted Date = 12/27/18 8:20 AM

Refer: 
https://docs.oracle.com/javase/8/docs/api/index.html?java/text/DateFormat.html

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java_spring_2019/src/80d90bcf5505788c0f100e330fb6b354d3132ddb/Java_2019/DateFormatDemo_DateFormat_Class/?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