From 4df3fff2aad8265232627ecb61c5dc8f9eecd40c Mon Sep 17 00:00:00 2001 From: lulunac27a <100660343+lulunac27a@users.noreply.github.com> Date: Thu, 7 Nov 2024 15:57:42 -0600 Subject: [PATCH] Format Java code --- .../datetimethymeleaf/DateTimeController.java | 111 ++-- .../datetimethymeleaf/entity/DateTime.java | 8 +- datetime.java | 515 +++++++++++++----- 3 files changed, 431 insertions(+), 203 deletions(-) diff --git a/datetime-thymeleaf/src/main/java/com/example/lulunac27a/datetimethymeleaf/DateTimeController.java b/datetime-thymeleaf/src/main/java/com/example/lulunac27a/datetimethymeleaf/DateTimeController.java index f207e5d..9728834 100644 --- a/datetime-thymeleaf/src/main/java/com/example/lulunac27a/datetimethymeleaf/DateTimeController.java +++ b/datetime-thymeleaf/src/main/java/com/example/lulunac27a/datetimethymeleaf/DateTimeController.java @@ -1,5 +1,9 @@ package com.example.lulunac27a.datetimethymeleaf; +import com.example.lulunac27a.datetimethymeleaf.entity.DateTime; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -7,19 +11,14 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import com.example.lulunac27a.datetimethymeleaf.entity.DateTime; - -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; - @Controller public class DateTimeController { + @GetMapping("/") // get request from home page public String dateTimeForm(Model model) { - DateTime dateTime = new DateTime();// create the date and time object + DateTime dateTime = new DateTime(); // create the date and time object model.addAttribute("enteredDateTime", dateTime); - LocalDateTime currentDateTime = LocalDateTime.now();// set the current date and time to now + LocalDateTime currentDateTime = LocalDateTime.now(); // set the current date and time to now dateTime.setYear(currentDateTime.getYear()); dateTime.setMonth(currentDateTime.getMonthValue()); dateTime.setDay(currentDateTime.getDayOfMonth()); @@ -29,20 +28,24 @@ public String dateTimeForm(Model model) { dateTime.setMillisecond((currentDateTime.getNano() / 1000000) % 1000); dateTime.setMicrosecond((currentDateTime.getNano() / 1000) % 1000); dateTime.setNanosecond(currentDateTime.getNano() % 1000); - LocalDateTime dateTimeValues = LocalDateTime.of(dateTime.getYear(), dateTime.getMonth(), dateTime.getDay(), - dateTime.getHour(), dateTime.getMinute(), dateTime.getSecond(), - dateTime.getMillisecond() * 1000000 + dateTime.getMicrosecond() * 1000 + dateTime.getNanosecond());// set - // date - // and - // time - // values + LocalDateTime dateTimeValues = LocalDateTime.of( + dateTime.getYear(), + dateTime.getMonth(), + dateTime.getDay(), + dateTime.getHour(), + dateTime.getMinute(), + dateTime.getSecond(), + dateTime.getMillisecond() * + 1000000 + + dateTime.getMicrosecond() * + 1000 + + + dateTime.getNanosecond()); // set date and time values model.addAttribute("currentDateTime", dateTimeValues); Instant currentUtcDateTime = Instant.now(); - LocalDateTime currentUtcDateTimeNow = LocalDateTime.ofInstant(currentUtcDateTime, ZoneId.of("UTC"));// set the - // current - // UTC date - // and time - // to now + LocalDateTime currentUtcDateTimeNow = LocalDateTime.ofInstant( + currentUtcDateTime, + ZoneId.of("UTC")); // set the current UTC date and time to now DateTime utcDateTimeValues = new DateTime(); utcDateTimeValues.setYear(currentUtcDateTimeNow.getYear()); utcDateTimeValues.setMonth(currentUtcDateTimeNow.getMonthValue()); @@ -50,41 +53,53 @@ public String dateTimeForm(Model model) { utcDateTimeValues.setHour(currentUtcDateTimeNow.getHour()); utcDateTimeValues.setMinute(currentUtcDateTimeNow.getMinute()); utcDateTimeValues.setSecond(currentUtcDateTimeNow.getSecond()); - utcDateTimeValues.setMillisecond((currentUtcDateTimeNow.getNano() / 1000000) % 1000); - utcDateTimeValues.setMicrosecond((currentUtcDateTimeNow.getNano() / 1000) % 1000); + utcDateTimeValues.setMillisecond( + (currentUtcDateTimeNow.getNano() / 1000000) % 1000); + utcDateTimeValues.setMicrosecond( + (currentUtcDateTimeNow.getNano() / 1000) % 1000); utcDateTimeValues.setNanosecond(currentUtcDateTimeNow.getNano() % 1000); - LocalDateTime utcDateTimeValuesNow = LocalDateTime.of(utcDateTimeValues.getYear(), utcDateTimeValues.getMonth(), - utcDateTimeValues.getDay(), utcDateTimeValues.getHour(), utcDateTimeValues.getMinute(), - utcDateTimeValues.getSecond(), utcDateTimeValues.getMillisecond() * 1000000 - + utcDateTimeValues.getMicrosecond() * 1000 + utcDateTimeValues.getNanosecond()); + LocalDateTime utcDateTimeValuesNow = LocalDateTime.of( + utcDateTimeValues.getYear(), + utcDateTimeValues.getMonth(), + utcDateTimeValues.getDay(), + utcDateTimeValues.getHour(), + utcDateTimeValues.getMinute(), + utcDateTimeValues.getSecond(), + utcDateTimeValues.getMillisecond() * + 1000000 + + utcDateTimeValues.getMicrosecond() * + 1000 + + + utcDateTimeValues.getNanosecond()); model.addAttribute("currentUtcDateTime", utcDateTimeValuesNow); - return "index";// return index page + return "index"; // return index page } @PostMapping("submit-form") // POST request from submitting the form - public String formatDateTime(@ModelAttribute("enteredDateTime") DateTime dateTime, Model model) {// format date and - // time using date - // and time format - // patterns + public String formatDateTime( + @ModelAttribute("enteredDateTime") DateTime dateTime, + Model model) { // format date and time using date and time format patterns model.addAttribute("enteredDateTime", dateTime); - LocalDateTime enteredDateTime = LocalDateTime.of(dateTime.getYear(), dateTime.getMonth(), dateTime.getDay(), - dateTime.getHour(), dateTime.getMinute(), dateTime.getSecond(), - dateTime.getMillisecond() * 1000000 + dateTime.getMicrosecond() * 1000 + dateTime.getNanosecond());// set - // entered - // date - // and - // time - // to - // form - // request - // values - model.addAttribute("dateTimeOutput", enteredDateTime);// add entered date and time values needed to print - // formatted date and time values - return "result";// return result page + LocalDateTime enteredDateTime = LocalDateTime.of( + dateTime.getYear(), + dateTime.getMonth(), + dateTime.getDay(), + dateTime.getHour(), + dateTime.getMinute(), + dateTime.getSecond(), + dateTime.getMillisecond() * + 1000000 + + dateTime.getMicrosecond() * + 1000 + + + dateTime.getNanosecond()); // set entered date and time to form request values + model.addAttribute("dateTimeOutput", enteredDateTime); // add entered date and time values needed to print + // formatted date and time values + return "result"; // return result page } @RequestMapping("/") // show index page when request is made from home page - public String showHomePage() {// show home page - return "index";// return index page + public String showHomePage() { // show home page + return "index"; // return index page } -} \ No newline at end of file +} diff --git a/datetime-thymeleaf/src/main/java/com/example/lulunac27a/datetimethymeleaf/entity/DateTime.java b/datetime-thymeleaf/src/main/java/com/example/lulunac27a/datetimethymeleaf/entity/DateTime.java index f9d0d87..97ad007 100644 --- a/datetime-thymeleaf/src/main/java/com/example/lulunac27a/datetimethymeleaf/entity/DateTime.java +++ b/datetime-thymeleaf/src/main/java/com/example/lulunac27a/datetimethymeleaf/entity/DateTime.java @@ -1,7 +1,8 @@ package com.example.lulunac27a.datetimethymeleaf.entity; -public class DateTime {// class with date and time information with milliseconds, microseconds and - // nanoseconds +public class DateTime { // class with date and time information with milliseconds, microseconds and + // nanoseconds + private int year; private int month; private int day; @@ -84,5 +85,4 @@ public int getNanosecond() { public void setNanosecond(int nanosecond) { this.nanosecond = nanosecond; } - -} \ No newline at end of file +} diff --git a/datetime.java b/datetime.java index d444e80..406da07 100644 --- a/datetime.java +++ b/datetime.java @@ -8,10 +8,11 @@ import java.util.Scanner; public class datetime { + public static void main(String[] args) { try (Scanner sc = new Scanner(System.in)) { - int year, month, day, hour, minute, second, millisecond, microsecond, nanosecond;// initialize date and time - // variables + int year, month, day, hour, minute, second, millisecond, microsecond, nanosecond; // initialize date and + // time variables DateTimeFormatter era1 = DateTimeFormatter.ofPattern("GGG"); // Format the date and time values with a // specified pattern for all supported formats DateTimeFormatter era2 = DateTimeFormatter.ofPattern("GGGG"); @@ -48,7 +49,8 @@ public static void main(String[] args) { DateTimeFormatter hourOfDay = DateTimeFormatter.ofPattern("H"); DateTimeFormatter minute1 = DateTimeFormatter.ofPattern("m"); DateTimeFormatter second1 = DateTimeFormatter.ofPattern("s"); - DateTimeFormatter fractionOfSecond = DateTimeFormatter.ofPattern("SSSSSSSSS"); + DateTimeFormatter fractionOfSecond = DateTimeFormatter.ofPattern( + "SSSSSSSSS"); DateTimeFormatter millisecondOfDay = DateTimeFormatter.ofPattern("A"); DateTimeFormatter nanosecondOfSecond = DateTimeFormatter.ofPattern("n"); DateTimeFormatter nanosecondOfDay = DateTimeFormatter.ofPattern("N"); @@ -61,11 +63,11 @@ public static void main(String[] args) { DateTimeFormatter timezoneOffset2 = DateTimeFormatter.ofPattern("ZZZZZ"); DateTimeFormatter timezoneOffsetZ1 = DateTimeFormatter.ofPattern("ZZZZ"); - try {// make sure date and time input is a vaild integer + try { // make sure date and time input is a vaild integer System.out.print("Year: "); year = sc.nextInt(); System.out.print("Month: "); - month = sc.nextInt();// 1 is January + month = sc.nextInt(); // 1 is January System.out.print("Day: "); day = sc.nextInt(); System.out.print("Hour: "); @@ -80,7 +82,8 @@ public static void main(String[] args) { microsecond = sc.nextInt(); System.out.print("Nanosecond: "); nanosecond = sc.nextInt(); - LocalDateTime enteredDateAndTime = LocalDateTime.of(year, month, day, hour, minute, second) + LocalDateTime enteredDateAndTime = LocalDateTime + .of(year, month, day, hour, minute, second) .withNano(millisecond * 1000000 + microsecond * 1000 + nanosecond); // Convert datetime of // GregorianCalendar object // to LocalDateTime object @@ -91,164 +94,374 @@ public static void main(String[] args) { // milliseconds + 1,000 (1 // thousand) * microseconds // + nanoseconds - ZonedDateTime enteredDateAndTimeTimezone = ZonedDateTime.of(enteredDateAndTime, ZoneId.systemDefault());// Get - // time - // zone - // of - // entered - // date - // and - // time - // values - // Print the entered date and time values in all supported formats + ZonedDateTime enteredDateAndTimeTimezone = ZonedDateTime.of( + enteredDateAndTime, + ZoneId.systemDefault()); // Get time zone of entered date and time values + // Print the entered date and time values in all supported formats System.out.println("\nEntered Date and Time Values:\n"); - System.out.println("Era: " + era1.format(enteredDateAndTime) + " (" + era2.format(enteredDateAndTime) - + ")" + " (" + era3.format(enteredDateAndTime) + ")"); // Print the date and time values with - // formatted date and time pattern - System.out.println( - "Year: " + year1.format(enteredDateAndTime) + " (" + year2.format(enteredDateAndTime) + ")"); - System.out.println("Era Year: " + yearEra.format(enteredDateAndTime) + " (" - + yearEra2.format(enteredDateAndTime) + ")"); - System.out.println("Day of Year: " + dayOfYear.format(enteredDateAndTime)); - System.out.println("Month of Year: " + monthOfYear.format(enteredDateAndTime) + " (" - + monthOfYear2.format(enteredDateAndTime) + ")" + " (" + monthOfYear3.format(enteredDateAndTime) - + ")" + " (" + monthOfYear4.format(enteredDateAndTime) + ")"); - System.out.println("Day of Month: " + dayOfMonth.format(enteredDateAndTime)); - System.out.println("Quarter: " + quarter.format(enteredDateAndTime) + " (" - + quarter2.format(enteredDateAndTime) + ")" + " (" + quarter3.format(enteredDateAndTime) + ")"); - System.out.println("ISO Week-based Year: " + weekBasedYear.format(enteredDateAndTime) + " (" - + weekBasedYear2.format(enteredDateAndTime) + ")"); - System.out.println("Week of Year: " + weekOfYear.format(enteredDateAndTime)); - System.out.println("Week of Month: " + weekOfMonth.format(enteredDateAndTime)); - System.out.println("Day of Week: " + dayOfWeek.format(enteredDateAndTime) + " (" - + dayOfWeek2.format(enteredDateAndTime) + ")" + " (" + dayOfWeek3.format(enteredDateAndTime) - + ")"); - System.out.println("Local Day of Week: " + localDayOfWeek.format(enteredDateAndTime) + " (" - + localDayOfWeek2.format(enteredDateAndTime) + ")" + " (" - + localDayOfWeek3.format(enteredDateAndTime) + ")" + " (" - + localDayOfWeek4.format(enteredDateAndTime) + ")"); - System.out.println("Local Week of Month: " + localWeekOfMonth.format(enteredDateAndTime)); + System.out.println( + "Era: " + + era1.format(enteredDateAndTime) + + " (" + + era2.format(enteredDateAndTime) + + ")" + + " (" + + era3.format(enteredDateAndTime) + + ")"); // Print the date and time values with formatted date and time pattern + System.out.println( + "Year: " + + year1.format(enteredDateAndTime) + + " (" + + year2.format(enteredDateAndTime) + + ")"); + System.out.println( + "Era Year: " + + yearEra.format(enteredDateAndTime) + + " (" + + yearEra2.format(enteredDateAndTime) + + ")"); + System.out.println( + "Day of Year: " + dayOfYear.format(enteredDateAndTime)); + System.out.println( + "Month of Year: " + + monthOfYear.format(enteredDateAndTime) + + " (" + + monthOfYear2.format(enteredDateAndTime) + + ")" + + " (" + + monthOfYear3.format(enteredDateAndTime) + + ")" + + " (" + + monthOfYear4.format(enteredDateAndTime) + + ")"); + System.out.println( + "Day of Month: " + dayOfMonth.format(enteredDateAndTime)); + System.out.println( + "Quarter: " + + quarter.format(enteredDateAndTime) + + " (" + + quarter2.format(enteredDateAndTime) + + ")" + + " (" + + quarter3.format(enteredDateAndTime) + + ")"); + System.out.println( + "ISO Week-based Year: " + + weekBasedYear.format(enteredDateAndTime) + + " (" + + weekBasedYear2.format(enteredDateAndTime) + + ")"); + System.out.println( + "Week of Year: " + weekOfYear.format(enteredDateAndTime)); + System.out.println( + "Week of Month: " + weekOfMonth.format(enteredDateAndTime)); + System.out.println( + "Day of Week: " + + dayOfWeek.format(enteredDateAndTime) + + " (" + + dayOfWeek2.format(enteredDateAndTime) + + ")" + + " (" + + dayOfWeek3.format(enteredDateAndTime) + + ")"); + System.out.println( + "Local Day of Week: " + + localDayOfWeek.format(enteredDateAndTime) + + " (" + + localDayOfWeek2.format(enteredDateAndTime) + + ")" + + " (" + + localDayOfWeek3.format(enteredDateAndTime) + + ")" + + " (" + + localDayOfWeek4.format(enteredDateAndTime) + + ")"); + System.out.println( + "Local Week of Month: " + localWeekOfMonth.format(enteredDateAndTime)); System.out.println("AM/PM: " + amPm.format(enteredDateAndTime)); - System.out.println("12 Hour Format " + hour12.format(enteredDateAndTime)); - System.out.println("0-11 Hour Format: " + hour0To11.format(enteredDateAndTime)); - System.out.println("24 Hour Format: " + hour24.format(enteredDateAndTime)); - System.out.println("Hour of Day: " + hourOfDay.format(enteredDateAndTime)); + System.out.println( + "12 Hour Format " + hour12.format(enteredDateAndTime)); + System.out.println( + "0-11 Hour Format: " + hour0To11.format(enteredDateAndTime)); + System.out.println( + "24 Hour Format: " + hour24.format(enteredDateAndTime)); + System.out.println( + "Hour of Day: " + hourOfDay.format(enteredDateAndTime)); System.out.println("Minute: " + minute1.format(enteredDateAndTime)); System.out.println("Second: " + second1.format(enteredDateAndTime)); - System.out.println("Fraction of Second: " + fractionOfSecond.format(enteredDateAndTime)); - System.out.println("Millisecond of Day: " + millisecondOfDay.format(enteredDateAndTime)); - System.out.println("Nanosecond: " + nanosecondOfSecond.format(enteredDateAndTime)); - System.out.println("Nanosecond of Day: " + nanosecondOfDay.format(enteredDateAndTime)); - System.out.println("Time Zone ID: " + timezoneId.format(enteredDateAndTimeTimezone)); - System.out.println("Time Zone: " + timezoneName2.format(enteredDateAndTimeTimezone) + " (" - + timezoneName.format(enteredDateAndTimeTimezone) + ")"); - System.out.println("Localized Time Zone Offset: " + timezoneOffset.format(enteredDateAndTimeTimezone) - + " (" + timezoneOffset2.format(enteredDateAndTimeTimezone) + ")"); - System.out.println("Time Zone Offset: " + timezoneOffsetZ.format(enteredDateAndTimeTimezone) + " (" - + timezoneOffsetX.format(enteredDateAndTimeTimezone) + ")" + " (" - + timezoneOffsetZ1.format(enteredDateAndTimeTimezone) + ")"); + System.out.println( + "Fraction of Second: " + fractionOfSecond.format(enteredDateAndTime)); + System.out.println( + "Millisecond of Day: " + millisecondOfDay.format(enteredDateAndTime)); + System.out.println( + "Nanosecond: " + nanosecondOfSecond.format(enteredDateAndTime)); + System.out.println( + "Nanosecond of Day: " + nanosecondOfDay.format(enteredDateAndTime)); + System.out.println( + "Time Zone ID: " + timezoneId.format(enteredDateAndTimeTimezone)); + System.out.println( + "Time Zone: " + + timezoneName2.format(enteredDateAndTimeTimezone) + + " (" + + timezoneName.format(enteredDateAndTimeTimezone) + + ")"); + System.out.println( + "Localized Time Zone Offset: " + + timezoneOffset.format(enteredDateAndTimeTimezone) + + " (" + + timezoneOffset2.format(enteredDateAndTimeTimezone) + + ")"); + System.out.println( + "Time Zone Offset: " + + timezoneOffsetZ.format(enteredDateAndTimeTimezone) + + " (" + + timezoneOffsetX.format(enteredDateAndTimeTimezone) + + ")" + + " (" + + timezoneOffsetZ1.format(enteredDateAndTimeTimezone) + + ")"); System.out.println("\nCurrent Date and Time Values:\n"); - } catch (InputMismatchException ex) {// if entered, date and time values are in the wrong format (not a - // valid integer) - System.out.println("\nInvalid date and time input.\nPrinting current date and time.\n");// print the - // error + } catch (InputMismatchException ex) { // if entered, date and time values are in the wrong format (not a + // valid integer) + System.out.println( + "\nInvalid date and time input.\nPrinting current date and time.\n"); // print the error } // Print the current date and time values in all supported formats ZonedDateTime dateAndTimeNow = ZonedDateTime.now(); // Get the current date and time based on local computer // date and time with local time zone - System.out.println("Current Era: " + era1.format(dateAndTimeNow) + " (" + era2.format(dateAndTimeNow) + ")" - + " (" + era3.format(dateAndTimeNow) + ")"); // Print the formatted date and time values in current - // local date and time - System.out.println( - "Current Year: " + year1.format(dateAndTimeNow) + " (" + year2.format(dateAndTimeNow) + ")"); - System.out.println("Current Era Year: " + yearEra.format(dateAndTimeNow) + " (" - + yearEra2.format(dateAndTimeNow) + ")"); - System.out.println("Current Day of Year: " + dayOfYear.format(dateAndTimeNow)); - System.out.println("Current Month of Year: " + monthOfYear.format(dateAndTimeNow) + " (" - + monthOfYear2.format(dateAndTimeNow) + ")" + " (" + monthOfYear3.format(dateAndTimeNow) + ")" - + " (" + monthOfYear4.format(dateAndTimeNow) + ")"); - System.out.println("Current Day of Month: " + dayOfMonth.format(dateAndTimeNow)); - System.out.println("Current Quarter: " + quarter.format(dateAndTimeNow) + " (" - + quarter2.format(dateAndTimeNow) + ")" + " (" + quarter3.format(dateAndTimeNow) + ")"); - System.out.println("Current ISO Week-based Year: " + weekBasedYear.format(dateAndTimeNow) + " (" - + weekBasedYear2.format(dateAndTimeNow) + ")"); - System.out.println("Current Week of Year: " + weekOfYear.format(dateAndTimeNow)); - System.out.println("Current Week of Month: " + weekOfMonth.format(dateAndTimeNow)); - System.out.println("Current Day of Week: " + dayOfWeek.format(dateAndTimeNow) + " (" - + dayOfWeek2.format(dateAndTimeNow) + ")" + " (" + dayOfWeek3.format(dateAndTimeNow) + ")"); - System.out.println("Current Local Day of Week: " + localDayOfWeek.format(dateAndTimeNow) + " (" - + localDayOfWeek2.format(dateAndTimeNow) + ")" + " (" + localDayOfWeek3.format(dateAndTimeNow) + ")" - + " (" + localDayOfWeek4.format(dateAndTimeNow) + ")"); - System.out.println("Current Local Week of Month: " + localWeekOfMonth.format(dateAndTimeNow)); + System.out.println( + "Current Era: " + + era1.format(dateAndTimeNow) + + " (" + + era2.format(dateAndTimeNow) + + ")" + + " (" + + era3.format(dateAndTimeNow) + + ")"); // Print the formatted date and time values in current local date and time + System.out.println( + "Current Year: " + + year1.format(dateAndTimeNow) + + " (" + + year2.format(dateAndTimeNow) + + ")"); + System.out.println( + "Current Era Year: " + + yearEra.format(dateAndTimeNow) + + " (" + + yearEra2.format(dateAndTimeNow) + + ")"); + System.out.println( + "Current Day of Year: " + dayOfYear.format(dateAndTimeNow)); + System.out.println( + "Current Month of Year: " + + monthOfYear.format(dateAndTimeNow) + + " (" + + monthOfYear2.format(dateAndTimeNow) + + ")" + + " (" + + monthOfYear3.format(dateAndTimeNow) + + ")" + + " (" + + monthOfYear4.format(dateAndTimeNow) + + ")"); + System.out.println( + "Current Day of Month: " + dayOfMonth.format(dateAndTimeNow)); + System.out.println( + "Current Quarter: " + + quarter.format(dateAndTimeNow) + + " (" + + quarter2.format(dateAndTimeNow) + + ")" + + " (" + + quarter3.format(dateAndTimeNow) + + ")"); + System.out.println( + "Current ISO Week-based Year: " + + weekBasedYear.format(dateAndTimeNow) + + " (" + + weekBasedYear2.format(dateAndTimeNow) + + ")"); + System.out.println( + "Current Week of Year: " + weekOfYear.format(dateAndTimeNow)); + System.out.println( + "Current Week of Month: " + weekOfMonth.format(dateAndTimeNow)); + System.out.println( + "Current Day of Week: " + + dayOfWeek.format(dateAndTimeNow) + + " (" + + dayOfWeek2.format(dateAndTimeNow) + + ")" + + " (" + + dayOfWeek3.format(dateAndTimeNow) + + ")"); + System.out.println( + "Current Local Day of Week: " + + localDayOfWeek.format(dateAndTimeNow) + + " (" + + localDayOfWeek2.format(dateAndTimeNow) + + ")" + + " (" + + localDayOfWeek3.format(dateAndTimeNow) + + ")" + + " (" + + localDayOfWeek4.format(dateAndTimeNow) + + ")"); + System.out.println( + "Current Local Week of Month: " + + localWeekOfMonth.format(dateAndTimeNow)); System.out.println("Current AM/PM: " + amPm.format(dateAndTimeNow)); - System.out.println("Current 12 Hour Format " + hour12.format(dateAndTimeNow)); - System.out.println("Current 0-11 Hour Format: " + hour0To11.format(dateAndTimeNow)); - System.out.println("Current 24 Hour Format: " + hour24.format(dateAndTimeNow)); - System.out.println("Current Hour of Day: " + hourOfDay.format(dateAndTimeNow)); + System.out.println( + "Current 12 Hour Format " + hour12.format(dateAndTimeNow)); + System.out.println( + "Current 0-11 Hour Format: " + hour0To11.format(dateAndTimeNow)); + System.out.println( + "Current 24 Hour Format: " + hour24.format(dateAndTimeNow)); + System.out.println( + "Current Hour of Day: " + hourOfDay.format(dateAndTimeNow)); System.out.println("Current Minute: " + minute1.format(dateAndTimeNow)); System.out.println("Current Second: " + second1.format(dateAndTimeNow)); - System.out.println("Current Fraction of Second: " + fractionOfSecond.format(dateAndTimeNow)); - System.out.println("Current Millisecond of Day: " + millisecondOfDay.format(dateAndTimeNow)); - System.out.println("Current Nanosecond: " + nanosecondOfSecond.format(dateAndTimeNow)); - System.out.println("Current Nanosecond of Day: " + nanosecondOfDay.format(dateAndTimeNow)); - System.out.println("Current Time Zone ID: " + timezoneId.format(dateAndTimeNow)); - System.out.println("Current Time Zone: " + timezoneName2.format(dateAndTimeNow) + " (" - + timezoneName.format(dateAndTimeNow) + ")"); - System.out.println("Current Localized Time Zone Offset: " + timezoneOffset.format(dateAndTimeNow) + " (" - + timezoneOffset2.format(dateAndTimeNow) + ")"); - System.out.println("Current Time Zone Offset: " + timezoneOffsetZ.format(dateAndTimeNow) + " (" - + timezoneOffsetX.format(dateAndTimeNow) + ")" + " (" + timezoneOffsetZ1.format(dateAndTimeNow) - + ")"); - Instant currentUtcDateAndTime = Instant.now();// Get the current UTC date and time using an Instant object - LocalDateTime utcDateAndTimeNow = LocalDateTime.ofInstant(currentUtcDateAndTime, ZoneOffset.UTC);// Convert - // from an - // Instant - // object - // to - // LocalDateTime - // object - System.out.println("Current UTC Era: " + era1.format(utcDateAndTimeNow) + " (" - + era2.format(utcDateAndTimeNow) + ")" + " (" + era3.format(utcDateAndTimeNow) + ")"); // Print the - // formatted - // date and - // time - // values in - // current - // local date - // and time - System.out.println("Current UTC Year: " + year1.format(utcDateAndTimeNow) + " (" - + year2.format(utcDateAndTimeNow) + ")"); - System.out.println("Current UTC Era Year: " + yearEra.format(utcDateAndTimeNow) + " (" - + yearEra2.format(utcDateAndTimeNow) + ")"); - System.out.println("Current UTC Day of Year: " + dayOfYear.format(utcDateAndTimeNow)); - System.out.println("Current UTC Month of Year: " + monthOfYear.format(utcDateAndTimeNow) + " (" - + monthOfYear2.format(utcDateAndTimeNow) + ")" + " (" + monthOfYear3.format(utcDateAndTimeNow) + ")" - + " (" + monthOfYear4.format(utcDateAndTimeNow) + ")"); - System.out.println("Current UTC Day of Month: " + dayOfMonth.format(utcDateAndTimeNow)); - System.out.println("Current UTC Quarter: " + quarter.format(utcDateAndTimeNow) + " (" - + quarter2.format(utcDateAndTimeNow) + ")" + " (" + quarter3.format(utcDateAndTimeNow) + ")"); - System.out.println("Current UTC ISO Week-based Year: " + weekBasedYear.format(utcDateAndTimeNow) + " (" - + weekBasedYear2.format(utcDateAndTimeNow) + ")"); - System.out.println("Current UTC Week of Year: " + weekOfYear.format(utcDateAndTimeNow)); - System.out.println("Current UTC Week of Month: " + weekOfMonth.format(utcDateAndTimeNow)); - System.out.println("Current UTC Day of Week: " + dayOfWeek.format(utcDateAndTimeNow) + " (" - + dayOfWeek2.format(utcDateAndTimeNow) + ")" + " (" + dayOfWeek3.format(utcDateAndTimeNow) + ")"); - System.out.println("Current UTC Local Day of Week: " + localDayOfWeek.format(utcDateAndTimeNow) + " (" - + localDayOfWeek2.format(utcDateAndTimeNow) + ")" + " (" + localDayOfWeek3.format(utcDateAndTimeNow) - + ")" + " (" + localDayOfWeek4.format(utcDateAndTimeNow) + ")"); - System.out.println("Current UTC Local Week of Month: " + localWeekOfMonth.format(utcDateAndTimeNow)); - System.out.println("Current UTC AM/PM: " + amPm.format(utcDateAndTimeNow)); - System.out.println("Current UTC 12 Hour Format " + hour12.format(utcDateAndTimeNow)); - System.out.println("Current UTC 0-11 Hour Format: " + hour0To11.format(utcDateAndTimeNow)); - System.out.println("Current UTC 24 Hour Format: " + hour24.format(utcDateAndTimeNow)); - System.out.println("Current UTC Hour of Day: " + hourOfDay.format(utcDateAndTimeNow)); - System.out.println("Current UTC Minute: " + minute1.format(utcDateAndTimeNow)); - System.out.println("Current UTC Second: " + second1.format(utcDateAndTimeNow)); - System.out.println("Current UTC Fraction of Second: " + fractionOfSecond.format(utcDateAndTimeNow)); - System.out.println("Current UTC Millisecond of Day: " + millisecondOfDay.format(utcDateAndTimeNow)); - System.out.println("Current UTC Nanosecond: " + nanosecondOfSecond.format(utcDateAndTimeNow)); - System.out.println("Current UTC Nanosecond of Day: " + nanosecondOfDay.format(utcDateAndTimeNow)); + System.out.println( + "Current Fraction of Second: " + fractionOfSecond.format(dateAndTimeNow)); + System.out.println( + "Current Millisecond of Day: " + millisecondOfDay.format(dateAndTimeNow)); + System.out.println( + "Current Nanosecond: " + nanosecondOfSecond.format(dateAndTimeNow)); + System.out.println( + "Current Nanosecond of Day: " + nanosecondOfDay.format(dateAndTimeNow)); + System.out.println( + "Current Time Zone ID: " + timezoneId.format(dateAndTimeNow)); + System.out.println( + "Current Time Zone: " + + timezoneName2.format(dateAndTimeNow) + + " (" + + timezoneName.format(dateAndTimeNow) + + ")"); + System.out.println( + "Current Localized Time Zone Offset: " + + timezoneOffset.format(dateAndTimeNow) + + " (" + + timezoneOffset2.format(dateAndTimeNow) + + ")"); + System.out.println( + "Current Time Zone Offset: " + + timezoneOffsetZ.format(dateAndTimeNow) + + " (" + + timezoneOffsetX.format(dateAndTimeNow) + + ")" + + " (" + + timezoneOffsetZ1.format(dateAndTimeNow) + + ")"); + Instant currentUtcDateAndTime = Instant.now(); // Get the current UTC date and time using an Instant object + LocalDateTime utcDateAndTimeNow = LocalDateTime.ofInstant( + currentUtcDateAndTime, + ZoneOffset.UTC); // Convert from an Instant object to LocalDateTime object + System.out.println( + "Current UTC Era: " + + era1.format(utcDateAndTimeNow) + + " (" + + era2.format(utcDateAndTimeNow) + + ")" + + " (" + + era3.format(utcDateAndTimeNow) + + ")"); // Print the formatted date and time values in current local date and time + System.out.println( + "Current UTC Year: " + + year1.format(utcDateAndTimeNow) + + " (" + + year2.format(utcDateAndTimeNow) + + ")"); + System.out.println( + "Current UTC Era Year: " + + yearEra.format(utcDateAndTimeNow) + + " (" + + yearEra2.format(utcDateAndTimeNow) + + ")"); + System.out.println( + "Current UTC Day of Year: " + dayOfYear.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC Month of Year: " + + monthOfYear.format(utcDateAndTimeNow) + + " (" + + monthOfYear2.format(utcDateAndTimeNow) + + ")" + + " (" + + monthOfYear3.format(utcDateAndTimeNow) + + ")" + + " (" + + monthOfYear4.format(utcDateAndTimeNow) + + ")"); + System.out.println( + "Current UTC Day of Month: " + dayOfMonth.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC Quarter: " + + quarter.format(utcDateAndTimeNow) + + " (" + + quarter2.format(utcDateAndTimeNow) + + ")" + + " (" + + quarter3.format(utcDateAndTimeNow) + + ")"); + System.out.println( + "Current UTC ISO Week-based Year: " + + weekBasedYear.format(utcDateAndTimeNow) + + " (" + + weekBasedYear2.format(utcDateAndTimeNow) + + ")"); + System.out.println( + "Current UTC Week of Year: " + weekOfYear.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC Week of Month: " + weekOfMonth.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC Day of Week: " + + dayOfWeek.format(utcDateAndTimeNow) + + " (" + + dayOfWeek2.format(utcDateAndTimeNow) + + ")" + + " (" + + dayOfWeek3.format(utcDateAndTimeNow) + + ")"); + System.out.println( + "Current UTC Local Day of Week: " + + localDayOfWeek.format(utcDateAndTimeNow) + + " (" + + localDayOfWeek2.format(utcDateAndTimeNow) + + ")" + + " (" + + localDayOfWeek3.format(utcDateAndTimeNow) + + ")" + + " (" + + localDayOfWeek4.format(utcDateAndTimeNow) + + ")"); + System.out.println( + "Current UTC Local Week of Month: " + + localWeekOfMonth.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC AM/PM: " + amPm.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC 12 Hour Format " + hour12.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC 0-11 Hour Format: " + hour0To11.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC 24 Hour Format: " + hour24.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC Hour of Day: " + hourOfDay.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC Minute: " + minute1.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC Second: " + second1.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC Fraction of Second: " + + fractionOfSecond.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC Millisecond of Day: " + + millisecondOfDay.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC Nanosecond: " + + nanosecondOfSecond.format(utcDateAndTimeNow)); + System.out.println( + "Current UTC Nanosecond of Day: " + + nanosecondOfDay.format(utcDateAndTimeNow)); } } }