Tuesday 15 January 2019

How to use getCalendar() and getTimeZone() methods of java.text.DateFormat class


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

DateFormatDemo.java

import java.text.DateFormat;
import java.util.Calendar;
import java.util.TimeZone;

public class DateFormatDemo
{
    public static void main(String[] args)
    {

        DateFormat dateFormat = DateFormat.getDateTimeInstance();
        /*
         * Returns:
         *
         * the calendar associated with this date/time formatter.
         */

        Calendar cal = dateFormat.getCalendar();
        System.out.println(cal.getTime());
       
        /*
         * Returns:the time zone associated with the calendar of
         * DateFormat.
         */

        TimeZone timeZone = dateFormat.getTimeZone();
        System.out.println(timeZone);
        System.out.println(timeZone.getDisplayName());

    }

}

Output:

Tue Jan 03 09:11:30 IST 1939
sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=6,lastRule=null]
India Standard Time

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java_spring_2019/src/4327965661b34e0cc17880946800be5f5d73f2dd/Java_2019/DateFormatDemo_getCalendar/?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