Converting date value
In this chapter you will learn:
Convert date value to long value in milliseconds
long getTime()
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMTvoid setTime(long time)
Sets to represent time that is time milliseconds after January 1, 1970 00:00:00 GMT.
The following code converts Date into milliseconds.
import java.util.Date;
// j a v a 2 s . c o m
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:
Convert Date value to String
String toString()
converts this Date object to a String of the form:
import java.util.Date;
/* j av a 2 s . co m*/
public class Main {
public static void main(String args[]) {
Date date = new Date();
System.out.println("Date is : " + date.toString());
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Date, Time