How to convert time value to YYYY-MM-DD format in Java?
long lastmodified = file.lastModified(); String lasmod = /*TODO: Transform it to this format YYYY-MM-DD*/
Something like:
Date lm = new Date(lastmodified); String lasmod = new SimpleDateFormat("yyyy-MM-dd").format(lm);
See javadoc for SimpleDateFormat .
final Date modDate = new Date(lastmodified); final SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd"); final String lasmod = f.format(modDate);
SimpleDateFormat
String lasmod = new SimpleDateFormat("yyyy-MM-dd").format(new Date(lastmodified));
Check out the correct template you want for SimpleDateFormat ... Maybe I included the wrong one from memory.
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));
Date d = new Date(lastmodified); DateFormat form = new SimpleDateFormat("yyyy-MM-dd"); String lasmod = form.format(d);