日期格式化

public class DateFomat{
public static void main(String[] args){
Date date = new Date();
System.out.println("date======="+date);

Calendar c = Calendar.getInstance();
c.setTime(date);

int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int d = c.get(Calendar.DATE);

String yearStr = String.valueOf(year);
String monthStr = String.valueOf(month);
String dateStr = String.valueOf(d);

if(year < 100){
yearStr = "0" + yearStr;
}
if(month < 10) {
monthStr = "0" +monthStr;
}
if(d<10) {
dateStr = "0" + dateStr;
}
System.out.printl(yearStr+"/"+monthStr+"/"+dateStr);
}
}

你可能感兴趣的:(C++,c,C#)