Date क्लास का getTime() मेथड एपोक समय (1 जनवरी 1970 00:00:00 GMT से मिलीसेकंड की संख्या) को पुनर्प्राप्त करता है और लौटाता है।
उदाहरण: Date क्लास का उपयोग
import java.util.Date;
public class Sample {
public static void main(String args[]){
// Date क्लास को इंस्टेंटिएट करना
Date date = new Date();
long msec = date.getTime();
System.out.println("मिली सेकंड: "+msec);
}
}
आउटपुट
मिली सेकंड: 1605160094688
Calendar क्लास का getTimeInMillis() मेथड एपोक समय (1 जनवरी 1970 00:00:00 GMT) से मिलीसेकंड में समय को पुनर्प्राप्त करता है और लौटाता है।
उदाहरण: Calendar क्लास का उपयोग
import java.util.Calendar;
public class Sample {
public static void main(String args[]){
// Calendar ऑब्जेक्ट बनाना
Calendar cal = Calendar.getInstance();
long msec = cal.getTimeInMillis();
System.out.println("मिली सेकंड: "+msec);
}
}
आउटपुट
मिली सेकंड: 1605160934357
Instant क्लास का toEpochMilli() मेथड एपोक से मिलीसेकंड लौटाता है।
उदाहरण: Instant क्लास का उपयोग
import java.time.Instant;
import java.time.ZonedDateTime;
public class Sample {
public static void main(String args[]){
// ZonedDateTime ऑब्जेक्ट बनाना
ZonedDateTime obj = ZonedDateTime.now();
Instant instant = obj.toInstant();
long msec = instant.toEpochMilli();
System.out.println("मिली सेकंड: "+msec);
}
}
आउटपुट
मिली सेकंड: 1605162474464