Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Challenge Question - Using GregorianCalendar and Date classes: (Use the GregorianCalendar class) Java API has the Date class and GregorianCalendar class in the java.util package,

image text in transcribed
image text in transcribed
Challenge Question - Using GregorianCalendar and Date classes: (Use the GregorianCalendar class) Java API has the Date class and GregorianCalendar class in the java.util package, which you can use to obtain the current date with specific details like current year, current month, current day of a date and so on. Write a program to perform these tasks: 1- Display the current year, month, and day. 2- Display the current date by using the toString() method from the Date class. 3- Display the current time-which is used to display the number of milliseconds-by using getTime() method from the Date class. We will use it in the step 17. 4- Display the current year by using get(GregorianCalendar.YEAR) method from the GregorianCalendar class. 5. Display the current year by using get(GregorianCalendar. MONTH) method from the GregorianCalendar class. Note: this method which is used for month- starts from 0 to 11 (O indicates January). You must take care about this issue for adding 1 in order to display 1 for January. 6- Display the current Day by using get(GregorianCalendar.DAY_OF_MONTH) method from the GregorianCalendar class. 7. Display the current Week by using get(GregorianCalendar.DAY_OF_WEEK) method from the GregorianCalendar class. 8- Display the current DAY OF WEEK IN MONTH by using get(GregorianCalendar.DAY OF WEEK_IN_MONTH) method from the GregorianCalendar class. 9. Display the current Day of Year by using get(GregorianCalendar.DAY_OF_YEAR) 10- Display the current Hour by using get(GregorianCalendar.HOUR) 11-Display the current Hour of day by using get(Gregorian Calendar.HOUR_OF_DAY) 12-Display the current MINUTE by using get(Gregorian Calendar.MINUTE) 13- Display the current Second by using get(Gregorian Calendar SECOND) 14- Display the current Millisecond by using get(Gregorian Calendar.MILLISECOND) 15- Display the current Week of month by using get(GregorianCalendar.WEEK_OF_MONTH) 16- Display the current Week of year by using get(Gregorian Calendar.WEEK_OF_YEAR) 17. Finally, use setTime() method which sets your current time (Step 3) and display your date and time using the toString method after adding these milliseconds (In for loop): 1, 10, 100, 1000, 10000 100000 1000000 10000000, 100000000 1000000000, 10000000000, and 100000000000 Here is the sample run: Current Date: Mon Jan 07 11:05:17 AST 2019 Current time (the number of milliseconds): 1546848317397 Current Year: 2019 Current Month: 1 Current Day: 7 Current Week: 2 Current DAY OF WEEK IN MONTH: 1 Current Day of Year: 7 Current Hour: 11 Current Hour of day: 11 Current MINUTE: 5 Current Second: 17 Current Millisecond: 470 Current Week of month: 2 Current Week of year: 2 The time after adding 1 millisecond(s): Mon Jan 07 11:05:17 AST 2019 The time after adding 10 millisecond(s): Mon Jan 07 11:05:17 AST 2019 The time after adding 100 millisecond(s): Mon Jan 07 11:05:17 AST 2019 The time after adding 1000 millisecond(s): Mon Jan 07 11:05:18 AST 2019 The time after adding 10000 millisecond(s) : Mon Jan 07 11:05:27 AST 2019 The time after adding 100000 millisecond(s): Mon Jan 07 11:06:57 AST 2019 The time after adding 1000000 millisecond(s): Mon Jan 07 11:21:57 AST 2019 The time after adding 10000000 millisecond(s): Mon Jan 07 13:51:57 AST 2019 The time after adding 100000000 millisecond(s) : Tue Jan 08 14:51:57 AST 2019 The time after adding 1000000000 millisecond(s) : Sat Jan 19 00:51:57 AST 2019 The time after adding 10000000000 millisecond(s): Fri May 03 04:51:57 AST 2019 The time after adding 100000000000 millisecond(s) : Wed Mar 09 20:51:57 AST 2022

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions