Click here to watch on Youtube:
https://www.youtube.com/watch?v=wWxiWEML1Cg&list=UUhwKlOVR041tngjerWxVccw
CalendarDemo.java
Output
Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/CalendarDemo_add_substract.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/CalendarDemo_add_substract
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/b1e669f4abac38a0eb65bfeb213dca88c58230cc/BasicJava_2018/CalendarDemo_add_substract/?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=wWxiWEML1Cg&list=UUhwKlOVR041tngjerWxVccw
CalendarDemo.java
import java.util.Calendar;
public class CalendarDemo
{
public static void main(String[] args)
{
Calendar cal = Calendar.getInstance();
System.out.println("The current date is = " + cal.getTime());
/*
* Parameters:
*
* field - the calendar field.
*
* amount - the amount of date or time to be added to the field.
*/
// subtract 3 months from the calendar
cal.add(Calendar.MONTH, -3);
System.out.println("3 months ago = " + cal.getTime());
// subtract 10 years from the calendar
cal.add(Calendar.YEAR, -10);
System.out.println("10 years ago = " + cal.getTime());
}
}
public class CalendarDemo
{
public static void main(String[] args)
{
Calendar cal = Calendar.getInstance();
System.out.println("The current date is = " + cal.getTime());
/*
* Parameters:
*
* field - the calendar field.
*
* amount - the amount of date or time to be added to the field.
*/
// subtract 3 months from the calendar
cal.add(Calendar.MONTH, -3);
System.out.println("3 months ago = " + cal.getTime());
// subtract 10 years from the calendar
cal.add(Calendar.YEAR, -10);
System.out.println("10 years ago = " + cal.getTime());
}
}
Output
The current date is = Sat Jun 30 09:07:01 IST 2018
3 months ago = Fri Mar 30 09:07:01 IST 2018
10 years ago = Sun Mar 30 09:07:01 IST 2008
3 months ago = Fri Mar 30 09:07:01 IST 2018
10 years ago = Sun Mar 30 09:07:01 IST 2008
Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/CalendarDemo_add_substract.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/CalendarDemo_add_substract
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/b1e669f4abac38a0eb65bfeb213dca88c58230cc/BasicJava_2018/CalendarDemo_add_substract/?at=master
See also:
No comments:
Post a Comment