(using the GregorianCalendar class) JavaAPI has the GregorianCalendar class in t
ID: 3610227 • Letter: #
Question
(using the GregorianCalendar class) JavaAPI has the GregorianCalendar class in thejava.util package that can be used toobtain the year, month, and day of a date. The no-arg constructorconstructs an instance for the current date, and the methodsget(GregorianCalendar.YEAR), get(GregorianCalendar.MONTH), andget(GregorianCalendar.DAY OF MONTH) returnthe year, month, and day. Write a program to perform two tasks:- Display the current year, month, and day
- The GregorianCalendar class has thesetTimeInMillis(long), which can be usedto set a specified elapsed time since January 1, 1970. Set thevalue to 1234567898765L and display theyear, month, and day.
Explanation / Answer
please rate - thanks note-January is month 0 import java.util.*; public class untitled1 { public static void main(String args[]) {int year,month,day; Calendar calendar = new GregorianCalendar(); year=calendar.get(calendar.YEAR); month=calendar.get(calendar.MONTH); day=calendar.get(calendar.DAY_OF_MONTH); System.out.println("Before Change:"); System.out.println("Todays Date: "+month+" "+day+" "+year); calendar.setTimeInMillis( 1234567898765L ); year=calendar.get(calendar.YEAR); month=calendar.get(calendar.MONTH); day=calendar.get(calendar.DAY_OF_MONTH); System.out.println("After Change:"); System.out.println(" Date: "+month+" "+day+" "+year); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.