A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java/java-program-to-display-time-in-different-country-format/ below:

Java Program to Display Time in Different Country Format

Java Program to Display Time in Different Country Format

Last Updated : 23 Jul, 2025

Locale class and DateFormat class is used to display time different Country Format.

The DateFormat class in Java is used for formatting dates. A specified date can be formatted into the Data/Time string. For example, a date can be formatted into: mm/dd/yyyy. Date Format classes are not synchronized. A Locale object logically consists of the fields like languages, script, country, variant, extensions.

The Java Locale class object represents a specific geographic, cultural, or political region.

Code:

Java
// Java Program to Display Time in Different Country Format

import java.text.DateFormat;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception
    {
        Date d1 = new Date();

        // creating a new locale for England Format
        Locale locEngland = new Locale("en", "ch");

        // initializing the date formatter and converting
        // the date
        DateFormat de = DateFormat.getDateInstance(
                        DateFormat.FULL, locEngland);

        System.out.println("England Format: "
                           + de.format(d1));

        // creating a new locale for Italian Format
        Locale locItalian = new Locale("it", "ch");

        // initializing the date formatter and converting
        // the date
        DateFormat di = DateFormat.getDateInstance(
                        DateFormat.FULL, locItalian);
      
        System.out.println("Italian Format: "
                           + di.format(d1));

        // creating a new locale for Russian Format
        Locale locRussian = new Locale("ru", "ch");

        // initializing the date formatter and converting
        // the date
        DateFormat dr = DateFormat.getDateInstance(
                        DateFormat.FULL, locRussian);
      
        System.out.println("Russian Format: "
                           + dr.format(d1));

        // creating a new locale for French Format
        Locale locFrench = new Locale("fr", "ch");

        // initializing the date formatter and converting
        // the date
        DateFormat df = DateFormat.getDateInstance(
                        DateFormat.FULL, locFrench);
      
        System.out.println("French Format: "
                           + df.format(d1));

        // creating a new locale for Spanish Format
        Locale locSpanish = new Locale("es", "ch");

        // initializing the date formatter and converting
        // the date
        DateFormat ds = DateFormat.getDateInstance(
                        DateFormat.FULL, locSpanish);
      
        System.out.println("Spanish Format: "
                           + ds.format(d1));

        // creating a new locale for chinese Format
        Locale locChinese = new Locale("cn", "ch");

        // initializing the date formatter and converting
        // the date
        DateFormat dc = DateFormat.getDateInstance(
                        DateFormat.FULL, locChinese);
      
        System.out.println("Chinese Format: "
                           + dc.format(d1));
    }
}

Output
England Format: Tuesday, 5 January 2021
Italian Format: marted?, 5 gennaio 2021
Russian Format: ???????, 5 ?????? 2021 ?.
French Format: mardi, 5 janvier 2021
Spanish Format: martes, 5 de enero de 2021
Chinese Format: 2021 Jan 5, Tue


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4