- 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
Display complete date and time information using Formatter in Java
Firstly, create a Formatter and Calendar object.
Formatter f = new Formatter(); Calendar cal = Calendar.getInstance();
Now display the current date and time. We have shown the date here in both lowercase and uppercase −
f = new Formatter(); System.out.println(f.format("
Date and Time (lowercase): %tc
", cal)); f = new Formatter(); System.out.println(f.format("Date and Time (uppercase): %Tc
", cal));
The following is an example −
Example
import java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar cal = Calendar.getInstance(); System.out.println("Current date and time: "+cal.getTime()); f = new Formatter(); System.out.println(f.format("
Date and Time (lowercase): %tc
", cal)); f = new Formatter(); System.out.println(f.format("Date and Time (uppercase): %Tc
", cal)); } }
Output
Current date and time: Mon Nov 26 07:24:21 UTC 2018 Date and Time (lowercase): Mon Nov 26 07:24:21 UTC 2018 Date and Time (uppercase): MON NOV 26 07:24:21 UTC 2018
- Related Articles
- Java Program to display date and time information in lowercase
- Java Program to display date and time information in uppercase
- Display just hour and minute using Formatter in Java
- Java Program to display date and time in Milliseconds
- Java Program to Display current Date and Time
- Display date and time in videos using OpenCV Python
- Java Program to display table with columns in the output using Formatter
- Display entire date time with milliseconds in Java
- Display nanoseconds with Java Date and Time Conversion Character
- Display seconds since the epoch with Java Date and Time Conversion Character
- Display the Asian and American Date Time with Date Object in JavaScript
- Vertically align numeric values in Java using Formatter
- How to display date and time picker in ReactNative?
- Display Date Time in dd MMM yyyy hh:mm:ss zzz format in Java
- Golang program to display current date and time

Advertisements