This question already has an answer here:

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

marked as duplicate by Stephen Kitt, JdeBP, Jeff Schaller, Mr Shunz, Stephen Harris Feb 12 at 0:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    if your timezone is UTC, then the timestamp of 14:55:55 is indeed ahead of the time you posted this (14:17:59) – Jeff Schaller Feb 11 at 14:22

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.