ISO时间类型示例:
2013-12-10T16:54:26.777Z
UTC时间类型示例:
Tue Dec 10 16:54:26 CST 2013
UNIX时间类型示例:
1386694466777
转换方法:
package test2;
/** 各类时间类型转换 */
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Transfer {
public static void main(String[] args) throws ParseException{
Long unix = 1386665666777L;
String iso = "2013-12-10T16:54:26.777Z";
System.out.println(unixToIso(unix));
System.out.println(unixAdd8(unix));
System.out.println(isoToUtc(iso));
System.out.println(isoToUnix(iso));
}
static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
public static String unixToIso(long unix){
Date time = new Date(unix);
return format.format(time);
}
public static long unixAdd8(long unix){
unix = unix +1000*60*60*8L;
return unix;
}
public static Date isoToUtc(String iso) throws ParseException{
return format.parse(iso);
}
public static long isoToUnix(String iso) throws ParseException{
Date time = format.parse(iso);
long uinx = time.getTime();
return uinx;
}
}
参考:
http://blog.csdn.net/mayixixi/article/details/8030473
和
unix时间戳(unix timestamp)与北京时间的互转方法
http://www.aiezu.com/system/linux/unix_timestamp_convert.html