- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to display Current Time in another Time Zone
To display the current time in another time zone, use the TimeZone class. To use it, import the following package.
import java.util.TimeZone;
Firstly, set the TimeZone.
cal.setTimeZone(TimeZone.getTimeZone("Europe/Sofia"));
Now, display the date using the Calendar object.
cal.get(Calendar.HOUR_OF_DAY) cal.get(Calendar.MINUTE) cal.get(Calendar.SECOND) cal.get(Calendar.MILLISECOND)
The following is the final example.
Example
import java.util.Calendar; import java.util.TimeZone; public class Demo { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Europe/Sofia TimeZone..."); cal.setTimeZone(TimeZone.getTimeZone("Europe/Sofia")); System.out.println("Hour = " + cal.get(Calendar.HOUR_OF_DAY)); System.out.println("Minute = " + cal.get(Calendar.MINUTE)); System.out.println("Second = " + cal.get(Calendar.SECOND)); System.out.println("Millisecond = " + cal.get(Calendar.MILLISECOND)); } }
Output
Europe/Sofia TimeZone... Hour = 11 Minute = 16 Second = 44 Millisecond = 354
- Related Articles
- Java Program to Display current Date and Time
- Display time zone with SimpleDateFormat(“z”) in Java
- Python Pandas - Convert Timestamp to another time zone
- Java Program to Get Current Date/Time
- Get the default Time Zone in Java
- Java Program to display computer time in milliseconds
- How to get current time zone in android using clock API class?
- How do I get the current time zone of MySQL?
- Java Program to display date and time in Milliseconds
- Java Program to display Time in 12-hour format
- Java Program to display time in 24-hour format
- Java Program to Display time in different country’s format
- Set the base time zone offset to GMT in Java
- How to return the time-zone offset in minutes for the current locale?
- Java Program to display date and time information in lowercase

Advertisements