问题

如何在Java中将当前日期转换为字符串?


#1 热门回答(182 赞)

String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());

#2 热门回答(56 赞)

// GET DATE & TIME IN ANY FORMAT
import java.util.Calendar;
import java.text.SimpleDateFormat;
public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";

public static String now() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());
}

取自here


#3 热门回答(24 赞)

// On the form: dow mon dd hh:mm:ss zzz yyyy
new Date().toString();

原文链接