Wednesday, 19 December 2018

How to use getDisplayName(Locale locale) method of java.util.TimeZone class


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

TimeZoneDemo.java

import java.util.Locale;
import java.util.TimeZone;

public class TimeZoneDemo
{
    public static void main(String[] args)
    {
        TimeZone timeZone = TimeZone.getDefault();

        Locale locale = new Locale("EN", "US");

        /*
         * Parameters:
         *
         * locale - the locale in which to supply the display name.
         *
         * Returns:
         *
         * the human-readable name of this time zone in the given
         * locale.
         */

        String displayName = timeZone.getDisplayName(locale);

        System.out.println("displayName = " + displayName);
    }
}

Output

displayName = India Standard Time

Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/TimeZoneDemo_getDisplayName_locale.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimeZoneDemo_getDisplayName_locale

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimeZoneDemo_getDisplayName_locale/?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
  • How to use getDisplayName(boolean daylight, int style, Locale locale) method of java.util.TimeZone


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

    TimeZoneDemo.java

    import java.util.Locale;
    import java.util.TimeZone;

    public class TimeZoneDemo
    {
        public static void main(String[] args)
        {
            TimeZone timezonedefault = TimeZone.getDefault();

            /*
             * Parameters:
             *
             * daylight - true specifying a Daylight Saving Time name, or
             * false specifying a Standard Time
             *
             * namestyle - either LONG or SHORTReturns:the human-readable
             * name of this time zone in the default locale.
             *
             * locale - the locale in which to supply the display name.
             *
             * Returns:
             *
             * the human-readable name of this time zone in the given
             * locale.
             */

            String displayName = timezonedefault.getDisplayName(true, TimeZone.LONG,
                    new Locale("EN", "US"));
            System.out.println("displayName = " + displayName);

            displayName = timezonedefault.getDisplayName(true, TimeZone.SHORT,
                    new Locale("EN", "US"));
            System.out.println("displayName = " + displayName);
        }
    }

    Output

    displayName = India Daylight Time
    displayName = IDT

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev2/java_basics/TimeZoneDemo_getDisplayName_DL_Style_locale.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimeZoneDemo_getDisplayName_DL_Style_locale

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimeZoneDemo_getDisplayName_DL_Style_locale/?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
  • How to use getDisplayName(boolean daylight, int style) method of java.util.TimeZone class


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

    TimeZoneDemo.java

    import java.util.TimeZone;

    public class TimeZoneDemo
    {
        public static void main(String[] args)
        {
            TimeZone timezonedefault = TimeZone.getDefault();

            /*
             * Parameters:
             *
             * daylight - true specifying a Daylight Saving Time name, or
             * false specifying a Standard Time
             *
             * namestyle - either LONG or SHORTReturns:the human-readable
             * name of this time zone in the default locale.
             *
             * Returns:
             *
             * the human-readable name of this time zone in the default
             * locale.
             */

            String displayName = timezonedefault.getDisplayName(true,
                    TimeZone.LONG);
            System.out.println("displayName LONG  = " + displayName);

            displayName = timezonedefault.getDisplayName(true, TimeZone.SHORT);
            System.out.println("displayName SHORT = " + displayName);
        }
    }

    Output

    displayName LONG  = India Daylight Time
    displayName SHORT = IDT

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev2/java_basics/TimeZoneDemo_getDisplayName_DL_Style.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimeZoneDemo_getDisplayName_DL_Style

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimeZoneDemo_getDisplayName_DL_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
  • Tuesday, 18 December 2018

    java.util.TimeZone class | Java Date and Time - Playlist

    How to use getAvailableIDs() and getAvailableIDs(int rawOffset) methods of java.util.TimeZone class


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

    TimeZoneDemo1.java

    import java.util.TimeZone;

    public class TimeZoneDemo1
    {
        public static void main(String[] args)
        {
            /*
             * Returns:an array of IDs.
             */

            String[] idArray = TimeZone.getAvailableIDs();
            for (String id : idArray)
            {
                System.out.println(id);
            }
        }
    }

    Output

    Africa/Abidjan
    Africa/Accra
    Africa/Addis_Ababa
    Africa/Algiers
    Africa/Asmara
    Africa/Asmera
    Africa/Bamako
    Africa/Bangui
    Africa/Banjul
    Africa/Bissau
    Africa/Blantyre
    Africa/Brazzaville
    Africa/Bujumbura
    Africa/Cairo

    ---
    ---
    ---

    IET
    IST
    JST
    MIT
    NET
    NST
    PLT
    PNT
    PRT
    PST
    SST
    VST

    TimeZoneDemo2.java

    import java.util.TimeZone;

    public class TimeZoneDemo2
    {
        public static void main(String[] args)
        {
            /*
             * Parameters:
             *
             * rawOffset - the given time zone GMT offset in milliseconds.
             *
             * Returns:an array of IDs, where the time zone for that ID
             * has the specified GMT offset. For example,
             * "America/Phoenix" and "America/Denver" both have GMT-07:00,
             * but differ in daylight saving behavior.
             */

            String[] availableIDArray = TimeZone.getAvailableIDs(3600000);

            System.out.println("Available Ids for offset are: ");
            for (String availableID : availableIDArray)
            {
                System.out.println(availableID);
            }
        }
    }

    Output

    Available Ids for offset are:
    Africa/Algiers
    Africa/Bangui
    Africa/Brazzaville
    Africa/Ceuta
    Africa/Douala
    Africa/Kinshasa
    Africa/Lagos
    Africa/Libreville

    ---
    ---

    Europe/Stockholm
    Europe/Tirane
    Europe/Vaduz
    Europe/Vatican
    Europe/Vienna
    Europe/Warsaw
    Europe/Zagreb
    Europe/Zurich
    MET
    Poland

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev2/java_basics/TimeZoneDemo_getAvailableIDs.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimeZoneDemo_getAvailableIDs

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimeZoneDemo_getAvailableIDs/?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
  • java.util.TimeZone class Introduction | Java Date and Time


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

    Click the below Image to Enlarge:
    java.util.TimeZone class Introduction | Java Date and Time

    TimeZoneDemo.java

    import java.util.TimeZone;

    public class TimeZoneDemo
    {
        public static void main(String[] args)
        {
            /*
             * Returns: the default TimeZone
             */

            TimeZone timeZone = TimeZone.getDefault();
            System.out.println("timeZone = " + timeZone);
           
            String displayName = timeZone.getDisplayName();
            System.out.println("displayName = " + displayName);
        }
    }

    Output

    timeZone = sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=6,lastRule=null]
    displayName = India Standard Time

    Refer: 
    docs.oracle.com/javase/8/docs/api/index.html?java/util/TimeZone.html

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev2/java_basics/TimeZoneDemo_Intro.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimeZoneDemo_Intro

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimeZoneDemo_Intro/?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
  • How to use setTime(long time) and setNanos(int n) methods of java.sql.Timestamp Class


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

    TimestampDemo.java

    import java.sql.Timestamp;

    public class TimestampDemo
    {

        public static void main(String[] args)
        {

            Timestamp timestamp = Timestamp.valueOf("2018-01-23 19:09:58.743");
            System.out.println(timestamp);

            long time = System.currentTimeMillis();

            /*
             * Parameters:
             *
             * time - the number of milliseconds.
             */

            timestamp.setTime(time);
            System.out.println(timestamp);

            /*
             * Parameters:
             *
             * n - the new fractional seconds component
             */

            timestamp.setNanos(3);
            System.out.println(timestamp);
        }

    }

    Output

    2018-01-23 19:09:58.743
    2018-11-25 08:33:21.444
    2018-11-25 08:33:21.000000003

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev2/java_basics/TimestampDemo_settime_nanos.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimestampDemo_settime_nanos

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimestampDemo_settime_nanos/?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
  • How to use from(Instant instant) method of java.sql.Timestamp Class | Java Date and Time


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

    TimestampDemo.java

    import java.sql.Timestamp;
    import java.time.Instant;

    public class TimestampDemo
    {

        public static void main(String[] args)
        {

            Instant instant = Instant.now();
            System.out.println("instant   = "+ instant);
           
            /*
             * Parameters:
             *
             * instant - the instant to convert
             *
             * Returns:
             *
             * an Timestamp representing the same point on the time-line
             * as the provided instant
             */

            Timestamp timestamp = Timestamp.from(instant);
            System.out.println("timestamp = "+timestamp);
        }

    }

    Output

    instant   = 2018-11-25T02:54:24.089Z
    timestamp = 2018-11-25 08:24:24.089

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev2/java_basics/TimestampDemo_from.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimestampDemo_from

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimestampDemo_from/?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
  • How to use valueOf(String s) and valueOf(LocalDateTime dateTime) methods of java.sql.Timestamp Class


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

    TimestampDemo.java

    import java.sql.Timestamp;
    import java.time.LocalDateTime;

    public class TimestampDemo
    {

        public static void main(String[] args)
        {

            LocalDateTime localDateTime = LocalDateTime.now();
            System.out.println("localDateTime = " + localDateTime);

            /*
             * Obtains an instance of Timestamp from a LocalDateTime
             * object, with the same year, month, day of month, hours,
             * minutes, seconds and nanos date-time value as the provided
             * LocalDateTime
             */

            Timestamp timestamp = Timestamp.valueOf(localDateTime);
            System.out.println(timestamp);

            /*
             * Parameters:
             *
             * s - timestamp in format yyyy-[m]m-[d]d hh:mm:ss[.f...]. The
             * fractional seconds may be omitted. The leading zero for mm
             * and dd may also be omitted.
             *
             * Returns:
             *
             * corresponding Timestamp value
             */

            timestamp = Timestamp.valueOf("2013-01-23 19:09:58.743");
            System.out.println(timestamp);
        }

    }

    Output

    localDateTime = 2018-11-13T09:59:07.900
    2018-11-13 09:59:07.9
    2013-01-23 19:09:58.743

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev2/java_basics/TimestampDemo_valueOf_methods.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimestampDemo_valueOf_methods

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimestampDemo_valueOf_methods/?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
  • How to use toInstant() and toLocalDateTime() methods of java.sql.Timestamp Class


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

    TimestampDemo.java

    import java.sql.Timestamp;
    import java.time.Instant;
    import java.time.LocalDateTime;

    public class TimestampDemo
    {

        public static void main(String[] args)
        {

            long millis = System.currentTimeMillis();
            Timestamp timestamp = new Timestamp(millis);
            System.out.println("timestamp = "+timestamp);

            /*
             * Converts this Timestamp object to an Instant.
             */

            Instant instant = timestamp.toInstant();
            System.out.println("instant = "+instant);

            /*
             * Converts this Timestamp object to a LocalDateTime.
             */

            LocalDateTime localDateTime = timestamp.toLocalDateTime();
            System.out.println("localDateTime = "+localDateTime);

        }

    }

    Output

    timestamp = 2018-11-12 10:14:13.501
    instant = 2018-11-12T04:44:13.501Z
    localDateTime = 2018-11-12T10:14:13.501

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev2/java_basics/TimestampDemo_toInstant.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimestampDemo_toInstant

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimestampDemo_toInstant/?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
  • How to use getTime() and getNanos() methods of java.sql.Timestamp Class | Java Date and Time


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

    TimestampDemo.java

    import java.sql.Timestamp;

    public class TimestampDemo
    {

        public static void main(String[] args)
        {
            long millis = System.currentTimeMillis();
            Timestamp timestamp = new Timestamp(millis);
            System.out.println(timestamp);

            /*
             * Returns:the number of milliseconds since January 1, 1970,
             * 00:00:00 GMT represented by this date.
             */

            long milliseconds = timestamp.getTime();
            System.out.println("milliseconds = " + milliseconds);

            /*
             * Gets this Timestamp object's nanos value.
             */

            long nanoseconds = timestamp.getNanos();
            System.out.println("nanoseconds  = " + nanoseconds);
        }

    }

    Output

    2018-11-09 09:51:20.999
    milliseconds = 1541737280999
    nanoseconds  = 999000000

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev2/java_basics/TimestampDemo_getTime_nanos.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimestampDemo_getTime_nanos

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimestampDemo_getTime_nanos/?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
  • How to format java.sql.Timestamp object | Java Date and Time


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

    TimestampDemo.java

    import java.sql.Timestamp;
    import java.text.SimpleDateFormat;

    public class TimestampDemo
    {

        public static void main(String[] args)
        {

            long millis = System.currentTimeMillis();
            Timestamp timestamp = new Timestamp(millis);
            System.out.println(timestamp);

            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH.mm.ss");

            /*
             * Parameters:
             *
             * date - the time value to be formatted into a time string.
             *
             * Returns:
             *
             * the formatted time string.
             */

            String formatedStrDate = sdf.format(timestamp);
            System.out.println(formatedStrDate);

        }

    }

    Output

    2018-11-07 09:38:42.398
    07/11/2018 09.38.42

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev2/java_basics/TimestampDemo_format.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimestampDemo_format

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimestampDemo_format/?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