public static void main(String[] args) {
Calendar now=Calendar.getInstance();
int month = now.get(Calendar.MONTH) + 1;
String m = ""; //
if(month < 10) { //
m = "0"+month;
}
String time = now.get(Calendar.YEAR)+ m + now.get(Calendar.DAY_OF_MONTH) +
now.get(Calendar.HOUR_OF_DAY)+now.get(Calendar.MINUTE)+
now.get(Calendar.SECOND)+now.get(Calendar.MILLISECOND);
System.out.println(time); }
这里的m是干嘛的 求注释
Calendar now=Calendar.getInstance();
int month = now.get(Calendar.MONTH) + 1;
String m = ""; //
if(month < 10) { //
m = "0"+month;
}
String time = now.get(Calendar.YEAR)+ m + now.get(Calendar.DAY_OF_MONTH) +
now.get(Calendar.HOUR_OF_DAY)+now.get(Calendar.MINUTE)+
now.get(Calendar.SECOND)+now.get(Calendar.MILLISECOND);
System.out.println(time); }
这里的m是干嘛的 求注释
System.out.println(dateFormat.format(new Date()));
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
//2011-10-19
import java.text.DateFormat;
import java.util.Locale;
public class DateDemo02
{
public static void main(String[] args)
{
DateFormat df1 = DateFormat.getDateInstance(DateFormat.YEAR_FIELD,new Locale("zh","CH"));
DateFormat df2 = DateFormat.getDateTimeInstance(DateFormat.YEAR_FIELD,DateFormat.ERA_FIELD,new Locale("zh","CH"));
System.out.println(df1.format(new Date()));
System.out.println(df2.format(new Date()));
}
}
System.out.println(dateFormat.format(new Date()));
一般需要导入import java.util.Date; import java.text.DateFormat;
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
小于10的1月==> 01