Convert date value to long value in milliseconds
long getTime()
- Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
void setTime(long time)
- Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.
Convert Date into milliseconds
import java.util.Date;
public class Main {
public static void main(String args[]) {
Date date = new Date();
System.out.println("Date is : " + date);
System.out.println("Milliseconds since January 1, 1970, 00:00:00 GMT : "
+ date.getTime());
}
}
The output:
Date is : Sat Oct 30 09:17:52 PDT 2010
Milliseconds since January 1, 1970, 00:00:00 GMT : 1288455472578
Home
Java Book
Essential Classes
Java Book
Essential Classes
Date:
- Date class
- Create Date object
- Compare two Date value
- Convert date value to long value in milliseconds
- Convert Date value to String