Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

About

A Java console application demonstrating date and time formatting, parsing, calculations, time zone conversions, and input validation using the Java Time API.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Time Explorer

Description

Java Time Explorer is a Java console application that demonstrates the capabilities of Java's modern date and time API.

The application provides eight interactive tools that allow users to display, format, parse, calculate, and convert dates and times through a menu-driven interface.

The project demonstrates date and time manipulation, user input validation, exception handling, and object-oriented programming.

Features

Features

  • Displays the current date, time, and combined date and time.
  • Formats dates using three different formats.
  • Parses user-entered text into date objects.
  • Calculates the difference between a past date and the current date.
  • Calculates the number of days remaining until a future date.
  • Calculates the duration between two times.
  • Converts meeting times between five international time zones.
  • Displays the current machine-friendly timestamp.
  • Validates user input and handles invalid dates, times, and menu selections.
  • Provides an interactive console menu.
Technologies Used

Technologies Used

  • Java
  • Java Date and Time API (java.time)
  • Apache Maven
  • IntelliJ IDEA
Project Structure

Project Structure

JavaTimeExplorer/
├── src/
│   ├── main/
│   │   └── java/
│   │       └── com/
│   │           └── javatimeexplorer/
│   │               ├── App.java
│   │               ├── Menu.java
│   │               └── TimeTools.java
│   └── test/
│       └── java/
├── pom.xml
├── .gitignore
├── output.png
└── README.md

Class Responsibilities

Class Responsibility
App Serves as the application's entry point.
Menu Displays the menu, processes user selections, and calls the appropriate time tools.
TimeTools Contains the methods responsible for date and time operations.
Installation and Setup

Installation and Setup

Requirements

Requirements

  • Java JDK
  • Apache Maven
  • IntelliJ IDEA or another Java IDE

The application's date and time functionality uses Java's built-in standard library and does not require additional external libraries.

Running the Application

Running the Application

  1. Clone or download the repository.
  2. Open the project in IntelliJ IDEA.
  3. Allow Maven to load the project configuration.
  4. Open App.java.
  5. Run the application's main method.
  6. Select a tool from the console menu.
  7. Follow the instructions displayed by the selected tool.
  8. Select option 9 to exit the application.
Application Menu

Application Menu

Java Time Explorer
------------------------------

1. Show current date and time
2. Format a date
3. Parse a date from text
4. Calculate age or event difference
5. Countdown to a future date
6. Calculate time duration
7. Convert time zones
8. Show current timestamp
9. Exit

------------------------------
Enter your choice:

The application returns to the main menu after completing an operation, allowing users to select additional tools without restarting the program.

Java Date and Time Classes

Java Date and Time Classes

The application demonstrates the following components of Java's date and time API:

Class Purpose
LocalDate Represents a date without a time or time zone.
LocalTime Represents a time without a date or time zone.
LocalDateTime Represents a combined date and time without a time zone.
DateTimeFormatter Formats and parses dates and times.
Period Calculates calendar-based differences in years, months, and days.
Duration Calculates time-based differences between temporal objects.
ChronoUnit Calculates differences using specific units of time.
ZonedDateTime Represents a date and time associated with a time zone.
ZoneId Identifies a time zone and its associated rules.
Instant Represents a specific moment on the universal timeline.
Time Zone Conversion

Time Zone Conversion

The application allows users to enter a meeting date and time in the Chicago time zone and displays the equivalent local time in the following locations:

Location Zone ID
Chicago America/Chicago
New York America/New_York
Los Angeles America/Los_Angeles
London Europe/London
Tokyo Asia/Tokyo

Java's ZonedDateTime and ZoneId classes allow the application to account for regional time differences, daylight saving time rules, and changes in calendar dates.

The application uses withZoneSameInstant() to preserve the original moment in time while displaying its equivalent in another time zone.

Application Output

Application Output

The console output demonstrates the application's interactive menu, date and time formatting, calculations, time zone conversions, and timestamp generation.

Program Screenshot

Java Time Explorer Output

Input Validation and Error Handling

Input Validation and Error Handling

The application uses conditional statements and Java exception handling to prevent invalid user input from causing unexpected program termination.

The application handles:

  • Invalid calendar dates.
  • Incorrect date formats.
  • Incorrect time formats.
  • Future dates entered into the age calculator.
  • Past dates entered into the countdown calculator.
  • Invalid meeting dates and times.
  • Invalid numeric menu selections.
  • Invalid alphabetical menu selections.

When invalid input is detected, the application displays a helpful error message and returns the user to the main menu.

Strict date parsing is used to prevent invalid calendar dates, such as February 30, from being accepted.

Conclusion

Conclusion

This project demonstrates how Java's modern date and time API can simplify working with time-related information.

The application provides practical experience with formatting, parsing, date calculations, time durations, time zone conversions, and timestamp generation.

The project also reinforces the importance of organized classes, reusable methods, input validation, and exception handling when developing reliable software.

About

A Java console application demonstrating date and time formatting, parsing, calculations, time zone conversions, and input validation using the Java Time API.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages