代码:
public static void main(String[] args) throws Exception{
/*
* 获取当前时间的办法
*/
//这个获取从1970年。。直到现在的毫秒数,可以用来计算程序执行时间(开头结尾各打个记号);
System.currentTimeMillis();
java.util.Date d = new java.util.Date();
Calendar c = Calendar.getInstance(); /*
* 将String转化为date类型
* public static Timestamp valueOf(String s)
* s - timestamp in format yyyy-[m]m-[d]d hh:mm:ss[.f...]. The fractional seconds may be omitted.
* The leading zero for mm and dd may also be omitted.
*/
String s = "1970-12-30 08:24:37.56";
Timestamp ts = Timestamp.valueOf(s);
System.out.println(ts); /*
* TimeZone时区处理,比如拿到日本现在hour:
* ID - 实现定义好的各种各样的字符串;
* public static TimeZone getTimeZone(String ID)
* ID - the ID for a TimeZone, either an abbreviation(缩写) such as "PST",
* a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00".
*/
Calendar cJapan = new GregorianCalendar(TimeZone.getTimeZone("Japan"));
System.out.println(cJapan.get(Calendar.HOUR_OF_DAY)); //查看那些timeZone ID可用:
for(String str : TimeZone.getAvailableIDs()){
System.out.println(str);
}
}
打印出来:
1970-12-30 08:24:37.56
1
Etc/GMT+12
Etc/GMT+11
Pacific/Midway
Pacific/Niue
Pacific/Pago_Pago
Pacific/Samoa
US/Samoa
America/Adak
America/Atka
Etc/GMT+10
HST
...
...