The getTime() method of Java Date class returns the number of milliseconds since January 1, 1970, 00:00:00 GTM which is represented by Date object.
Syntax:
public long getTime()
Parameters: The function does not accept any parameter.
Return Value: It returns the number of milliseconds since January 1, 1970, 00:00:00 GTM.
Exception: The function does not throws any exception.
Program below demonstrates the above mentioned function:
import java.util.Date;
import java.util.Calendar;
public class GfG {
public static void main(String[] args)
{
Calendar c1 = Calendar.getInstance();
c1.set(Calendar.MONTH, 11);
c1.set(Calendar.DATE, 05);
c1.set(Calendar.YEAR, 1996);
Date dateOne = c1.getTime();
System.out.println("Date: " + dateOne);
System.out.println(dateOne.getTime());
}
}
|
Output:
Date: Thu Dec 05 09:29:39 UTC 1996
849778179420
import java.util.Date;
import java.util.Calendar;
public class GfG {
public static void main(String[] args)
{
Calendar c1 = Calendar.getInstance();
c1.set(Calendar.MONTH, 11);
c1.set(Calendar.DATE, 05);
c1.set(Calendar.YEAR, 2000);
Date dateOne = c1.getTime();
System.out.println("Date: " + dateOne);
System.out.println(dateOne.getTime());
}
}
|
Output:
Date: Tue Dec 05 09:29:40 UTC 2000
976008580370
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!