import java.util.Calendar; /** * * @author LiuTingYu */ public class getDate {
/** Creates a new instance of getTime */ public getDate() { } public static void main(String[] args) { Calendar now = Calendar.getInstance(); int year = now.get(Calendar.YEAR); int month = now.get(Calendar.MONTH)+1; int day = now.get(Calendar.DAY_OF_MONTH); System.out.println("今天是:"+year+"-"+month+"-"+day);
}
} 接分!!
import java.util.Calendar; /** * * @author TonieLau */ public class getDate {
public getDate() { } public static void main(String[] args) { Calendar now = Calendar.getInstance(); int year = now.get(Calendar.YEAR); int month = now.get(Calendar.MONTH)+1; int day = now.get(Calendar.DAY_OF_MONTH); if(month<10){ System.out.println("今天是:"+year+"-0"+month+"-"+day); } else { System.out.println("今天是:"+year+"-"+month+"-"+day); }
}
}这个就完善了
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); Date d = new Date();//获取当前时间 System.out.println(sdf.format(d));
/**
*
* @author LiuTingYu
*/
public class getDate {
/** Creates a new instance of getTime */
public getDate() {
}
public static void main(String[] args) {
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH)+1;
int day = now.get(Calendar.DAY_OF_MONTH);
System.out.println("今天是:"+year+"-"+month+"-"+day);
}
}
接分!!
/**
*
* @author TonieLau
*/
public class getDate {
public getDate() {
}
public static void main(String[] args) {
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH)+1;
int day = now.get(Calendar.DAY_OF_MONTH);
if(month<10){
System.out.println("今天是:"+year+"-0"+month+"-"+day);
} else {
System.out.println("今天是:"+year+"-"+month+"-"+day);
}
}
}这个就完善了
Date d = new Date();//获取当前时间
System.out.println(sdf.format(d));