1

I'm building a java service that modifies the "Last Modified" field of some of the files it works with.

The service keeps copies of files in a folder, it periodically checks a database for changes, if it finds a file whose "last modified" timestamp in the database is newer than the one on the file system then it deletes the file from the file system, downloads a fresh copy and sets the "last modified" field on the file to match the one from the database.

This all works as expected. In the code I query an SQL timestamp from the database, get the time as a Long and pass that into the file.setLastModified() method of the file object.
This works as expected, and when running comparisons both timestamps match as expected.
However, when I access the server via ssh and run ls -l in the folder containing the files the last modified timestamp just says "2019"; BUT, if I run the ls --full-time command then the full timestamp is displayed and is correct.
Why is this?
Is there some other flag I need to set when setting the timestamp on the file?
This is only an annoyance right now, I'm just curious as to why it looks this way.
Here's a screenshot of what it looks like:

enter image description here

mal
  • 143
  • 4

1 Answers1

4

Your files are probably “from the future” — i.e. their timestamps are later than the current time on the system where you run ls. In such cases, ls shows the year rather than the time.

This is specified by POSIX: ls shows the date and time for files modified in the last six months, the date and year for anything else. “In the future” isn’t “in the last six months”, so you see the year.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164