| |
8.26.7.DateFormat.format(), DateFormat.parse() |
|
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
public class MainClass {
public static void main(String[] argv) {
Date d1 = new Date(1000000000000L);
System.out.println("d1 = " + d1.toString());
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
String s = df.format(d1);
System.out.println(s);
try {
Date d2 = df.parse(s);
System.out.println("parsed = " + d2.toString());
} catch (ParseException pe) {
System.out.println("parse exc");
}
}
}
|
|
d1 = Sat Sep 08 18:46:40 PDT 2001
08/09/01
parsed = Sat Sep 08 00:00:00 PDT 2001 |
|