Click here to watch on Youtube:
https://www.youtube.com/watch?v=dodLf5rsLFU&list=UUhwKlOVR041tngjerWxVccw
CalendarDemo.java
Output
Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/CalendarDemo_compareTo.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/CalendarDemo_compareTo
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/b1e669f4abac38a0eb65bfeb213dca88c58230cc/BasicJava_2018/CalendarDemo_compareTo/?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
https://www.youtube.com/watch?v=dodLf5rsLFU&list=UUhwKlOVR041tngjerWxVccw
CalendarDemo.java
import java.util.Calendar;
public class CalendarDemo
{
public static void main(String[] args)
{
Calendar cal1 = Calendar.getInstance();
System.out.println("Current date = " + cal1.getTime());
Calendar cal2 = Calendar.getInstance();
cal2.set(Calendar.YEAR, 2030);
System.out.println("future date = " + cal2.getTime());
/*
* Parameters:
*
* anotherCalendar - the Calendar to be compared.
*
* Returns:
*
* the value 0 if the time represented by the argument is
* equal to the time represented by this Calendar; a value
* less than 0 if the time of this Calendar is before the time
* represented by the argument; and a value greater than 0 if
* the time of this Calendar is after the time represented by
* the argument.
*/
int result = cal1.compareTo(cal2);
System.out.println("result = " + result);
}
}
public class CalendarDemo
{
public static void main(String[] args)
{
Calendar cal1 = Calendar.getInstance();
System.out.println("Current date = " + cal1.getTime());
Calendar cal2 = Calendar.getInstance();
cal2.set(Calendar.YEAR, 2030);
System.out.println("future date = " + cal2.getTime());
/*
* Parameters:
*
* anotherCalendar - the Calendar to be compared.
*
* Returns:
*
* the value 0 if the time represented by the argument is
* equal to the time represented by this Calendar; a value
* less than 0 if the time of this Calendar is before the time
* represented by the argument; and a value greater than 0 if
* the time of this Calendar is after the time represented by
* the argument.
*/
int result = cal1.compareTo(cal2);
System.out.println("result = " + result);
}
}
Output
Current date = Wed Jul 04 09:29:23 IST 2018
future date = Thu Jul 04 09:29:24 IST 2030
result = -1
future date = Thu Jul 04 09:29:24 IST 2030
result = -1
Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/CalendarDemo_compareTo.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/CalendarDemo_compareTo
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/b1e669f4abac38a0eb65bfeb213dca88c58230cc/BasicJava_2018/CalendarDemo_compareTo/?at=master
See also:
No comments:
Post a Comment