import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; public class TestDateAndTime { public static void main(String[] args) { // (1) 拿到当前系统时间 System.out.println(System.currentTimeMillis()); // 19700101 到 现在过了多少毫秒 Date d = new Date(); Calendar c = Calendar.getInstance(); // (2) 字符串到日期 String s = "1970-12-30 08:24:37.0"; Timestamp ts = Timestamp.valueOf(s); System.out.println(ts); // (3) 拿到日本时间 Calendar cJapan = new GregorianCalendar(TimeZone.getTimeZone("Japan")); System.out.println(cJapan.get(Calendar.HOUR_OF_DAY)); System.out.println(cJapan.get(Calendar.MINUTE)); for (String str : TimeZone.getAvailableIDs()) { System.out.println(str); } } }