Wednesday, 18 July 2018

How to use setTime(Date date) method of Java.util.calendar class?


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

CalendarDemo.java

import java.util.Calendar;
import java.util.Date;

public class CalendarDemo
{
    public static void main(String[] args)
    {
        Calendar cal = Calendar.getInstance();     
        cal.set(2013,3,10);
        System.out.println("Before setting Time = " + cal.getTime());

        Date date = new Date();
       
        /*
         * Parameters:
         *
         * date - the given Date.
         */

        cal.setTime(date);

        System.out.println("After setting Time  = " + cal.getTime());
    }
}

Output

Before setting Time = Wed Apr 10 09:47:03 IST 2013
After setting Time  = Thu Jun 28 09:47:11 IST 2018

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

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

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