Mon Jun 15 10:29:51 AM MDT 2026 Today is but a day, there’s nothing else that comes from it. It will be whatever it wants to be and we cannot do anything about it. If I had complete control over my life, what would we need for a higher power to be watching over us? We need to have that higher being in place though, at least I think we do. Without Him watching over us, we might screw up bad beyond the point of no longer being able to do whatever it is we need to accomplish in this life. So confused at times, I’m not sure where this confusion comes from though. I need to be able to make sense of something in this life. If I don’t? Then what is the purpose of life? I don’t get it. Sure there are a ton of things I don’t get in this life, I guess that’s just how this life is meant to be? I don’t know. I wish … oh how I wish I could have it make sense to me. But it doesn’t ever want to make sense for me. Do you see the problem I’m facing here? The dilemma I have at times? If you don’t, we...
Sometimes you want to be able to change the created date of a file. Don't ask me WHY you would ever need to do this, but well here's a way in Java.
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.time.*;
public class ChangeCreatedDate {
public static void main(String[] args) throws IOException {
if (args.length == 2) {
File file = new File(args[0]);
if (file.exists()) {
file.setLastModified(System.currentTimeMillis());
} else {
file.createNewFile();
}
}
LocalDate date = LocalDate.parse(args[1]);
LocalTime time = LocalTime.now();
Path file = Paths.get(args[0]);
FileTime fileTime = FileTime.fromMillis(getMillisecondsSince1970(date, time));
Files.setAttribute(file, "creationTime", fileTime);
}
public static long getMillisecondsSince1970(LocalDate date, LocalTime time) {
ZonedDateTime zonedDateTime = ZonedDateTime.of(
date,
time,
ZoneId.systemDefault());
return zonedDateTime.toInstant().toEpochMilli();
}
}
Looking back at it, I wonder why I didn't make it so you could update the time as well as the date. Interesting. I mean it would make sense to be able to update both the date AND time. But I didn't have that in this section of code. Oh well, I'm sure I'll change it someday.
I find it interesting that we're updating an attribute of the file. One would think it would be someplace else, or easier to access directly on the file object itself. But well, it's not. So that's just that.
Comments
Post a Comment