It seems to be simple, but so far I'm not trying to work. Basically I want to convert the file time in milliseconds from 1970 (usually) to TemporalAccessor, and then to RFC 1123 string . However, although I can get compilation examples, I get runtime errors. For instance:
// Just using 0 milliseconds time for quick and easy test
System.out.println(java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME.format(
FileTime.from(0, TimeUnit.MILLISECONDS).toInstant()));
leads to
Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: DayOfMonth
I tried several variations of this using different classes (Instant, LocalTime, Date), but I get the same result.
What is the right way to do this?
UPDATE: The initial question was technically given, and I realized that I needed to be more specific. I have already “successfully” converted milliseconds to an instance of TemporalAccessor, however, it seems that this object was not in a healthy state. I had a runtime error while trying to use it to accomplish what I really needed, which made me believe that I did not create it properly. Something is missing. Either this, or there is an error in the RFC 1123 format.
UPDATE 2: Thanks Sleafar for posting a working answer.
Using his example, I did it a little differently, because for some reason I really wanted the "full" TemporalAccessor to do something. Here is a working example:
TemporalAccessor time = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0),
ZoneId.systemDefault());
System.out.println(
java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME.format(time));
user2426985
source
share