日期处理类在jdk中的演变史
最开始只提供了Date类后来由于Date类太简单,例如你要计算下一个时区的时间就不行了,所以就提供了个Calendar类。如果想把一个时间按照一定跟是输出就用DateFormat,但是一般来说是用他的子类SimpleDateformat。
把一个时间转换为GMT时间。
public static String formatGMTDate(Date date) { return format.format(date); } private static final SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); static { format.setTimeZone(TimeZone.getTimeZone("GMT")); }返回指定时间的时间对象:
Calendar c = Calendar.getInstance(); c.set(1984, 7, 5, 8, 59); System.out.println(f.format(c.getTime()));
页:
[1]