【问题标题】:How to reset time to 00:00:00 and change to timeMilis? [duplicate]如何将时间重置为 00:00:00 并更改为 timeMilis? [复制]
【发布时间】:2017-03-08 03:43:48
【问题描述】:

我有疑问: 长timeInMillis = 1488943098615; //-> 2017 年 3 月 8 日星期三 10:18:18

如何从1488943098615 切换(2017 年 3 月 8 日星期三 10:18:18)-> (timeInMillis)(2017 年 3 月 8 日星期三 00:00:00 >)。这意味着要花一整天的时间。消除小时和分钟。

【问题讨论】:

标签: android date time calendar datetimepicker


【解决方案1】:
Calendar cal = Calendar.getInstance(); // defaults to currentTimeInMs
//cal.setTimeInMillis(myCurrentTime); //if you have a timestamp already
cal.set(Calendar.HOUR_OF_DAY, 0); //reset just the hour and minute parts
cal.set(Calendar.MINUTE, 0);      //leaving the same date
long msAtMidnight = cal.getTimeInMillis();

【讨论】:

  • 谢谢!我需要这个
【解决方案2】:

你得到当前日期然后你 sub () 当前日期与小时 = 0,分钟 = 0,秒 = 0

重要代码

Date currentDate = miliSecond (yyyyMMddHHmmss)
Date currentStartDate = miliSecond(yyyyMMdd000000)
miliSecondSub = currentDate - currentStartDate;
Date now = Date(miliSecondSub)

【讨论】:

  • 谢谢!我已经做到了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多