How can I transform a time value into 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 the javadoc for SimpleDateFormat .
final Date modDate = new Date(lastmodified);
final SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
final String lasmod = f.format(modDate);
String lasmod = new SimpleDateFormat("yyyy-MM-dd").format(new Date(lastmodified));
查找SimpleDateFormat所需的正确模式...我可能在内存中包含了错误的模式。
Date d = new Date(lastmodified);
DateFormat form = new SimpleDateFormat("yyyy-MM-dd");
String lasmod = form.format(d);
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));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.