1\
Calendar c=Calendar.getInstance();
c.get(Calendar.YEAR)+"/"+(c.get(Calendar.MONTH)+1);//2017/12
2\
SimpleDateFormat dateFormat=null;
Date date = null;
dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
date=dateFormat.parse("2017-12-12 13:12:00");
}catch(Exception e){
}
System.out.println("date:"+date);//Tue Dec 12 13:12:00 CST 2017
3\
//24小时制
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//12小时制
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String date1 = "2017-04-23 16:45:12";
try {
sdf.parse(date1);
System.out.println(sdf.format(sdf.parse(date1))); //2017-04-23 16:45:12
System.out.println(sdf1.format(sdf.parse(date1))); //2017-04-23 04:45:12
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
4\
var d = new Date();
var mm = d.getMonth()+1;
mm = mm<10?”0”+mm:mm;
var yyyymm = d.getFullYear() + “/” + mm;//2017/12
5\
获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS”
function getNowFormatDate() {
var date = new Date();
var seperator1 = “-“;
var seperator2 = “:”;
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = “0” + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = “0” + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
+ ” ” + date.getHours() + seperator2 + date.getMinutes()
+ seperator2 + date.getSeconds();
return currentdate;
}