Tuesday 15 January 2019

How to format the date using Date time formatter in java with date style, time style and locale


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

DateFormatDemo.java

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

public class DateFormatDemo
{
    public static void main(String[] args)
    {
        Locale locale = Locale.getDefault();
        System.out.println(locale);
        /*
         * Parameters:
         *
         * dateStyle - the given date formatting style.
         * timeStyle - the given time formatting style.
         * aLocale - the given locale.
         *
         * Returns:
         *
         * a date/time formatter.
         */

        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,
                DateFormat.LONG, locale);

        String strDate = dateFormat.format(new Date());
        System.out.println(strDate);
    }
}

Output:

en_US
December 31, 2018 10:05:41 AM IST

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

Github Link:
https://github.com/ramram43210/Java_Spring_2019/tree/master/Java_2019/DateFormatDemo_getDateTimeInstance_date_locale-time_style

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