long lastmodified = file.lastModified();
String lasmod = /*TODO: Transform it to this format YYYY-MM-DD*/
views:
2586answers:
5
+12
A:
Something like:
Date lm = new Date(lastmodified);
String lasmod = new SimpleDateFormat("yyyy-MM-dd").format(lm);
See the javadoc for SimpleDateFormat.
sblundy
2008-10-22 16:45:28
Just to state the obvious here, if you're doing this in the context of a long-lived object or in a loop, you probably want to construct the SimpleDateFormat object once and reuse it.
nsayer
2008-10-22 16:52:02
Although beware - SimpleDateFormat is not thread-safe
oxbow_lakes
2008-10-22 16:58:25
+2
A:
String lasmod = new SimpleDateFormat("yyyy-MM-dd").format(new Date(lastmodified));
Look up the correct pattern you want for SimpleDateFormat... I may have included the wrong one from memory.
Instantsoup
2008-10-22 16:46:55
A:
Date d = new Date(lastmodified);
DateFormat form = new SimpleDateFormat("yyyy-MM-dd");
String lasmod = form.format(d);
Paul Tomblin
2008-10-22 16:47:00
+2
A:
final Date modDate = new Date(lastmodified);
final SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
final String lasmod = f.format(modDate);
Lars Westergren
2008-10-22 16:47:19
+1
A:
Try:
import java.text.SimpleDateFormat;
import java.util.Date;
long lastmodified = file.lastModified();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String lastmod = format.format(new Date(lastmodified));
James Cooper
2008-10-22 16:49:46