如何分别检索时间字段?

我使用此代码将当前时间转换为整数格式

 long x1=new Date().getTime(); 
 int x=(int) x1;

现在我想从整数分别获得实际的日期值(年,月,日期,小时,分钟)int x

我怎样才能做到这一点?


慕工程0101907
浏览 157回答 2
2回答

子衿沉夜

您可以使用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;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java