Java: Time in milliseconds to HTTP format?
date, http, java
Solution
SimpleDateFormat sdf =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String httpDate = sdf.format(new Date(file.lastModified()));
Problem
I have a File object and I want to get the last modified date of that file into HTTP format. The format is in GMT time and is like: ``` Mon, 10 Feb 2014 16:17:37 GMT ``` I know java.io.File has a method `lastModified()` which returns the time in milliseconds. I can also pass that time in milliseconds to the constructor of the java.util.Date class. But what is the easiest way to get a string in HTTP format? Thanks.