【问题标题】:Android Get Current Date (with time being 0:00:000) in Milliseconds?Android以毫秒为单位获取当前日期(时间为0:00:000)?
【发布时间】:2012-01-15 00:19:18
【问题描述】:

我想以毫秒为单位获取时间归零的当前日期。

例如,如果今天是下午 12:69,我想获取今天日期的时间(以毫秒为单位),没有时间...意思是午夜之后的时间(如果可行,则为 1 毫秒或 0)。

我正在使用 Calendar 对象,但似乎无法弄清楚如何将时间部分归零。

【问题讨论】:

  • 你能详细说明你的问题吗假设现在时间是 7:08:08 现在应​​该为你输出什么
  • 顺便说一句,如果它显示“12:69”,你一定有一个非常奇怪的时钟:p
  • @Jave - 大声笑...对不起,我打字很快,时间并不重要...哈哈。不过这真的很有趣。 :)

标签: android date time


【解决方案1】:

以下是如何将日历的时间归零:

Calendar today = Calendar.getInstance();
today.set(Calendar.MILLISECOND, 0);
today.set(Calendar.SECOND, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.HOUR_OF_DAY, 0);

【讨论】:

    【解决方案2】:

    没有日历:

    long d = new Date().getTime();
    int offset = TimeZone.getDefault().getOffset(d);
    d = ((d + offset)/ 86400000l) * 86400000l - offset;
    

    【讨论】:

      猜你喜欢
      • 2011-09-03
      • 1970-01-01
      • 2011-04-19
      • 2011-10-25
      • 2017-02-20
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多