我使用此代码将当前时间转换为整数格式 long x1=new Date().getTime();
int x=(int) x1;现在我想从整数分别获得实际的日期值(年,月,日期,小时,分钟)int x。我怎样才能做到这一点?
2 回答

子衿沉夜
TA贡献1828条经验 获得超3个赞
您可以使用System.currentTimeMillis()返回当前时间(以毫秒为单位),然后可以做一些数学运算来计算小时,分钟和秒。
long totalMolilliseconds = System.currentTimeMillis();
long totalSeconds = totalMolilliseconds / 1000;
long currentSeconds = totalSeconds % 60;
long totalMinutes = totalSeconds / 60;
long currentMinutes = totalMinutes % 60;
long totalHours = totalMinutes / 60;
long currentHours = totalHours % 24;
添加回答
举报
0/150
提交
取消