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.
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()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With