
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program to Display time in different country’s format
In this article, we will understand how to display time in different country’s format. Java does not have a built-in Date class, but we can import the java.time package to work with the date and time API. The package includes many date and time classes.
Below is a demonstration of the same −
Suppose our input is −
Run the program
The desired output would be −
The England Format is: Friday, 18 March 2022 The Italian Format is: venerdì, 18 marzo 2022
Algorithm
Step 1 - START Step 2 - Declare an object of LocalDateTime namely date. Step 3 - Define the values. Step 4 - Define different date time formats using DateTimeFormatter objects. Step 5 - Display the different date time formats of different countries. Step 6 - Stop
Example 1
Here, we bind all the operations together under the ‘main’ function.
import java.text.DateFormat; import java.util.*; public class Demo { public static void main(String[] args) throws Exception{ System.out.println("The required packages have been imported"); Date date_time = new Date(); Locale England_time = new Locale("en", "ch"); DateFormat de = DateFormat.getDateInstance(DateFormat.FULL, England_time); System.out.println("\nThe England Format is: " + de.format(date_time)); Locale Italy_time = new Locale("it", "ch"); DateFormat di = DateFormat.getDateInstance(DateFormat.FULL, Italy_time); System.out.println("The Italian Format is: " + di.format(date_time)); } }
Output
The required packages have been imported The England Format is: Tuesday, March 29, 2022 The Italian Format is: marted?, 29. marzo 2022
Example 2
Here, we encapsulate the operations into functions exhibiting object oriented programming.
import java.text.DateFormat; import java.util.*; public class Demo { static void Time_formats(Date date_time ){ Locale England_time = new Locale("en", "ch"); DateFormat de = DateFormat.getDateInstance(DateFormat.FULL, England_time); System.out.println("\nThe England Format is: " + de.format(date_time)); Locale Italy_time = new Locale("it", "ch"); DateFormat di = DateFormat.getDateInstance(DateFormat.FULL, Italy_time); System.out.println("The Italian Format is: " + di.format(date_time)); } public static void main(String[] args) throws Exception{ System.out.println("The required packages have been imported"); Date date_time = new Date(); System.out.println("A date object has been defined"); Time_formats(date_time); } }
Output
The required packages have been imported The England Format is: Tuesday, March 29, 2022 The Italian Format is: marted?, 29. marzo 2022
- Related Articles
- Golang program to display time in different country’s format
- Java Program to display Time in 12-hour format
- Java Program to display time in 24-hour format
- Java Program to Display Dates of Calendar Year in Different Format
- Java Program to Format time in AM-PM format
- Java Program to format time using Custom Format
- Java Program to format time with DateFormat.MEDIUM
- Java Program to format time with DateFormat.LONG
- Java Program to display Current Time in another Time Zone
- Java Program to display computer time in milliseconds
- Java Program to format date time with Join
- Java Program to parse Time using custom format
- Display Date Time in dd MMM yyyy hh:mm:ss zzz format in Java
- Java Program to display date with day name in short format
- Java Program to display date and time in Milliseconds

Advertisements