海报here表示日期始终为UTC时间。但是,如果我创建了一个Date(),创建一个Calendar并使用日期设置日历时间,那么该时间仍然是我的本地时间(并且我不在UTC时间 我已经通过打印日历的日期在一个循环中,每个循环减去一个小时,现在是5月19日晚上11点,在日期变为5月18日之前需要24个循环,目前是UTC的1点,所以如果日历设置正确, 14个环路。如何设置UTC时间的日历?
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
int index = 0;
for(; index > -30; index--)
{
System.out.println(index);
System.out.println(dateFormatter.format(calendar.getTime()));
System.out.println();
calendar.add(Calendar.HOUR, -1);
}
可能重复:http://stackoverflow.com/q/2403109/668970 – developer 2011-05-19 13:16:59
我不相信这是一个傻瓜。完全不同的API。 – 2013-01-01 04:05:32