- 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
Get current time information in Java
Import the following package for to work with Calendar class in Java,
import java.util.Calendar;
Create a calendar class now.
Calendar cal = Calendar.getInstance();
To display entire time information, use the following fields.
cal.get(Calendar.HOUR_OF_DAY) cal.get(Calendar.HOUR) cal.get(Calendar.MINUTE) cal.get(Calendar.SECOND) cal.get(Calendar.MILLISECOND)
The following is the final example.
Example
import java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // current date and time System.out.println(cal.getTime().toString()); // time information System.out.println("Hour (24 hour format) : " + cal.get(Calendar.HOUR_OF_DAY)); System.out.println("Hour (12 hour format) : " + cal.get(Calendar.HOUR)); 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
Mon Nov 19 13:42:44 UTC 2018 Hour (24 hour format) : 13 Hour (12 hour format) : 1 Minute : 42 Second : 44 Millisecond : 621
- Related Articles
- How to get current Time in Java 8?
- Java Program to Get Current Date/Time
- How to get the current date and time in Java?
- How to get current date/time in milli seconds in Java?
- Get current date/time in seconds - JavaScript?
- How to get current location provider information in android?
- Get current thread in Java
- How to get current time in milliseconds in Python?
- Get current time and date on Android
- Golang program to get current time zone
- Java Program to display Current Time in another Time Zone
- How to get current date and time in Python?
- How to get current date and time in JavaScript?
- How to get current time and date in C++?
- Get JFrame window size information in Java

Advertisements