date 转 int :
long nowTime = System.currentTimeMillis()/1000;
Integer nowTimeInt = new Long(nowTime).intValue();int 转 date:
long nowTimeLong=new Long(nowTimeInt).longValue()*1000;
DateFormat ymdhmsFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowTimeStr = ymdhmsFormat.format(nowTimeLong);
Date nowTimeDate = ymdhmsFormat.parse(nowTimeStr);可以看到:int 转 date 其实是: int > long > string > date;
本文介绍了如何在Java中将日期类型转换为整型,并反过来将整型转换回日期类型的具体步骤。首先通过获取当前时间戳并除以1000得到一个长整型时间值,再将该长整型转换为整型。接着将整型时间值重新转换为长整型,使用SimpleDateFormat格式化为字符串,最后将字符串解析回日期类型。

1626

被折叠的 条评论
为什么被折叠?



