- 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 date and time in Milliseconds
Firstly, to display date and time, import the following package.
import java.util.Date;
Display the current date using Date class.
Date currentDate = new Date();
Let us now get milliseconds since Jan. 1, 1970 GMT
long res = currentDate.getTime();
The following is an example.
Example
import java.util.Date; public class Example { public static void main(String args[]) { Date currentDate = new Date(); System.out.println("Current date = "+currentDate); // getting milliseconds since Jan. 1, 1970 GMT long res = currentDate.getTime(); System.out.println("Milliseconds = " + res); } }
Output
Current date = Mon Nov 19 05:32:19 UTC 2018 Milliseconds = 1542605539301
Advertisements