小编Ash*_*wan的帖子

File.lastmodified()生成错误的日期和月份

我使用File.getlastmodified()来获取文件的最后修改,但由于某种原因(可能是UIT),其打印错误的日期和月份(年份很好)

我最后用上述方法修改并将其保存到Long

//理想情况下,这应该将最后修改的内容转换为人类可交易的格式,但返回的月份和日期错误

喜欢----> 27/11/2018

显示为-> 2018年10月28日

c = Calendar.getInstance(); 

Long epoch = files[i].lastModified();

epoch+=32400L;

c.setTimeInMillis(epoch); //im converting the milliseconds to human readable formate

int year=c.get(Calendar.YEAR);
int month=c.get(Calendar.MONTH);
int day=c.get(Calendar.DATE);

Run Code Online (Sandbox Code Playgroud)

java file

0
推荐指数
1
解决办法
57
查看次数

标签 统计

file ×1

java ×1