
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to get current date/time in milli seconds in Java?
The getTime() method of the Date class retrieves and returns the epoch time (number of milliseconds from Jan 1st 1970 00:00:00 GMT0.
Example
import java.util.Date; public class Sample { public static void main(String args[]){ //Instantiating the Date class Date date = new Date(); long msec = date.getTime(); System.out.println("Milli Seconds: "+msec); } }
Output
Milli Seconds: 1605160094688
The getTimeInMillis() method of the calendar class retrieves and returns the time in milli seconds from the epochepoch time (Jan 1st 1970 00:00:00 GMT).
Example
import java.util.Calendar; public class Sample { public static void main(String args[]){ //Creating the Calendar object Calendar cal = Calendar.getInstance(); long msec = cal.getTimeInMillis(); System.out.println("Milli Seconds: "+msec); } }
Output
Milli Seconds: 1605160934357
The toEpochMilli() method of the Instant class returns the milliseconds from the epoch.
Example
import java.time.Instant; import java.time.ZonedDateTime; public class Sample { public static void main(String args[]){ //Creating the ZonedDateTime object ZonedDateTime obj = ZonedDateTime.now(); Instant instant = obj.toInstant(); long msec = instant.toEpochMilli(); System.out.println("Milli Seconds: "+msec); } }
Output
Milli Seconds: 1605162474464
- Related Articles
- How to get current date/time in seconds in JavaScript?
- Get current date/time in seconds - JavaScript?
- Java Program to get Milli seconds from Instant
- How to get the current date and time in Java?
- Java Program to Get Current Date/Time
- How to get (format) date and time from mill seconds in Java?
- 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++?
- How to get the current date in Java?
- How to get current Time in Java 8?
- How to get current date and time from internet in android?
- How to get current date and time from internet in iOS?
- How to get the current local date and time in Kotlin?
- Add seconds to current date using Calendar.add() method in Java

Advertisements