Coding Style Use descriptive variable names Use consistent i
Coding Style: Use descriptive variable names. Use consistent indentation. Use standard Java naming conventions for variableAndMethodNames, ClassNames, CONSTANT NAMES. Include a reasonable amount of comments. Invoking System.currentTimeMillis returns a long integer giving the elapsed time in milliseconds since midnight of January 1,1970. The value returned is based on UTC time, which is 5 hours ahead of Central Daylight Time. Using the value returned by System.currentTimeMillis), compute the current date and time, adjusting for Central Daylight Time and truncating to the second. You can use any operators or any methods of the Math class, but do NOT call any methods that come with Java related to dates, times, calendars, etc. other than System.currentTimeMillis(). You may wish to use the long data type for all integer variables (otherwise be careful to use int only when you are sure the values will fit), and note that literal numeric values can be designated as long by appending an L, i.e., 5L is a long but 5 is an int. Your computations will need to take leap years into account. A leap year is any year that: a. is divisible by 400, OR b. is divisible by 4 but not divisible by 100 Display the current date and time in the following format. Current date and time is September 29, 2016 at 10:10:01 am Next, using the fact that January 1, 1970 was a Thursday, compute the current day of the week. (Hint: For the computations, represent Sunday as 0, Monday as 1, ..., Saturday as 6.) Do NOT use Zeller\'s congruence (if you have heard of it) or call any methods that come with Java related to dates, times, calendars, etc. Then modify the above output format so that the new output format becomes: Current date and time is Thursday, September 29, 2016 at 10:10:01 am
Solution
class currentdateandtime { public static void main(String args[]) { int day1, month1, year1; int seconds, minutes, hours; GregorianCalendar date = new GregorianCalendar(); day1 = date.get(Calendar.DAY_OF_MONTH); month1 = date.get(Calendar.MONTH); year1 = date.get(Calendar.YEAR); seconds = date.get(Calendar.SECOND); minutes = date.get(Calendar.MINUTE); hours = date.get(Calendar.HOUR); System.out.println(\"The current date is \"+day1+\"/\"+(month1+1)+\"/\"+year1); System.out.println(\"The Current time is \"+hours+\" : \"+minutes+\" : \"+seconds); } }