获取一年的每一天的所有全时 [英] Get all full hours of every day of a year
本文介绍了获取一年的每一天的所有全时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在命令行上获取/打印给定年份的每一天的每一个小时,例如。 2011但是我很难在Java中编码。
I need to get / print on command line every full hour of every day of a given year, e.g. 2011 but I am struggling to code it in Java.
有没有人编码过这个问题?
Has anybody ever coded this issue?
推荐答案
这应该可以工作:
final DateFormat df = DateFormat.getDateTimeInstance();
final Calendar c = Calendar.getInstance();
c.clear();
for (c.set(2011, Calendar.JANUARY, 1, 0, 0, 0);
c.get(Calendar.YEAR) == 2011;
c.add(Calendar.HOUR_OF_DAY, 1))
System.out.println(df.format(c.getTime()));
注意,例如,输出中的这个细微之处:
Notice, for example, this subtlety in the output:
Oct 30, 2011 12:00:00 AM
Oct 30, 2011 1:00:00 AM
Oct 30, 2011 2:00:00 AM
Oct 30, 2011 2:00:00 AM
Oct 30, 2011 3:00:00 AM
这篇关于获取一年的每一天的所有全时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文