日期:2014-05-18 浏览次数:21240 次
Calendar c=Calendar.getInstance();
for(int i=0;i<24;i++){//当前时间循环24小时减下去
System.out.println(c.get(Calendar.HOUR_OF_DAY));
c.add(Calendar.HOUR_OF_DAY, -i);
}
Date date = new Date();
int nowHour = date.getHours();
int[] hours = new int[24];
for (int i = 0; i < hours.length; i++) {
hours[i] = (nowHour++)%24;
}
for (int j = 0; j < hours.length; j++) {
System.out.println(hours[j]);
}
Date date = new Date();
// System.out.println(date);
Calendar c = new GregorianCalendar();
c.setTime(date);//给Calendar对象设置时间
int hour = c.get(Calendar.HOUR_OF_DAY);//取得当前时间的时数
import java.util.Calendar;
public class Get24Hours {
public static void main(String[] args) {
Integer[] hours=new Integer[24];
for (int i = 0; i < 24; i++) {
Calendar calendar=Calendar.getInstance();
calendar.add(Calendar.HOUR_OF_DAY, i);
hours[i]=calendar.get(Calendar.HOUR_OF_DAY);
}
for (int i = 0; i < hours.length; i++) {
System.out.print(hours[i]+",");