1、获取小时
注意设置时区,calendar方法设置的时区可能会失效,一般用SimpleDateFormat
public String getHour(long ts) {
Date date1 = new Date(ts);
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
calendar.setTime(date1);
return String.valueOf(Calendar.HOUR_OF_DAY);
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+8"));
String t = simpleDateFormat.format(ts);
org.apache.commons.lang.time.DateUtils
�