【发布时间】:2014-11-25 12:33:24
【问题描述】:
对于我的 Android 应用程序中的复活节彩蛋,我必须将当前日期与存储的日期进行比较 - 我只需要知道它是否是正确的月份。
我知道System.currentTimeMillis() 是获取当前时间的最快方法,但现在我需要从中获取当前月份。我避免了字符串比较,因为它的已知缺陷。
我糟糕的实现有效,但看起来确实不正确和高效:
if (Integer.parseInt((String) DateFormat.format("MM",System.currentTimeMillis()))==12) //xmas "easteregg"
xmasBool=true;
有没有更优雅的解决方案?
【问题讨论】: