【问题标题】:Android convert milliseconds to hoursAndroid将毫秒转换为小时
【发布时间】:2015-03-06 14:35:26
【问题描述】:

我在 String 中有毫秒,我想从中获取小时和分钟。

这是我的code

String ms = "1425652847915";
int t = Integer.parseInt(ms);

Calendar c = Calendar.getInstance();
c.set(Calendar.MILLISECOND, t);

int  h = c.get(Calendar.HOUR_OF_DAY);
int  m = c.get(Calendar.MINUTE); 

但我得到了这个error

java.lang.NumberFormatException:无法将“1425652847915”解析为整数

有什么建议吗?

【问题讨论】:

  • @WarrenFaith 对初学者程序员很好一定很难
  • @quixotrykd 他很好 imo
  • 真的吗???我可以阅读错误信息!我知道它是从什么来的!!!但我无法解析大整数!感谢您的投票!

标签: java android time calendar parseint


【解决方案1】:

显然1425652847915 大于Integer.MAX_VALUE 但您仍需要为Calendar 设置时间

long t = Long.parseLong("1425652847915");
Calendar c = Calendar.getInstance();
c.setTimeInMillis(t);

【讨论】:

    猜你喜欢
    • 2018-11-16
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    相关资源
    最近更新 更多