Why is Java (Android?) setting my file's last modified date to tomorrow?

本秂侑毒 提交于 2019-12-05 14:38:51

What does your test device/emulator show the current date and time as? It sounds like they're just set incorrectly.

Is the time zone on the device set to something other than your local time for instance?

Alexey

I work on the similar problem (lastModified date is changed sometimes without touching to the file) but not find a workaround.

I create a test for create file, store value returned by lastModified function and check this value again after some actions to the phone (my device is Galaxy S).

I found that lastModified uses internal cache while work and this cache can be cleared by enabling/disabling USB mode (if a file is on SDCard). I think also that this Cache is cleared automatically after some interval. If cache has been cleared then the function read real value stored in the filesystem.

If you change the timezone on the device and clear the cache then lastModified function will return another time (the difference depends on the new timezone, for example, if you change from GMT+3 to GMT+4 then the difference is 1 hour).

This problem is 100% reproducible.

Assuming that you are using java.io.File.lastModified(), to get the last-modified timestamp, you are getting the number of milliseconds since 00:00:00 GMT, January 1, 1970. The timestamp is implicitly GMT/UTC based.

You should check other files on your phone that may be modified and created using FileOutputStream (possibly your photos). If they too have a modified date set to tomorrow, then I suggest you file a bug report to the manufacturers of your phone.

I assume it's a bug related to the phone because you said that this does not happen on your Nexus One.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!