js obtain the current time yyyy-MM-dd hh: mm: ss
Date.prototype.Format = function (fmt) { // author: meizz
var o = {
"M+": this.getMonth() + 1, // 月份
"d+": this.getDate(), // 日
"h+": this.getHours(), // 小时
"m+": this.getMinutes(), // 分
"s+": this.getSeconds(), // 秒
"q+": Math.floor((this.getMonth() + 3) / 3), // 季度
"S": this.getMilliseconds() // 毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
var Time = new Date().Format("yyyy-MM-dd hh:mm:ss");
A: need to reference java.util.date
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat ( "yyyy / MM / dd HH: mm: ss"); // can easily modify the date format
String hehe = dateFormat.format (now);
System.out.println(hehe);
Two: you need to reference
Calendar java.util.Calendar.getInstance()
code show as below
Calendar c = Calendar.getInstance (); // can be individually modified for each time-domain
int year = c.get (Calendar.YEAR);
int = month The c.get (the Calendar.MONTH) + 1'd; // get the month less than the current one, it is necessary + 1'd
int = DATE c.get (Calendar.DATE);
// int hour = c.get (Calendar.HOUR_OF_DAY);
// int = c.get minute (Calendar.MINUTE);
/ / int second = c.get (Calendar.SECOND) ;
String nowtime=year + "-" + month + "-" + date;
Three: the current month all dates
List list = new ArrayList();
Calendar aCalendar = Calendar.getInstance(Locale.CHINA);
int year = aCalendar.get(Calendar.YEAR);//年份
int month = aCalendar.get(Calendar.MONTH) + 1;//月份
int day = aCalendar.getActualMaximum(Calendar.DATE);
for (int i = 1; i <= day; i++) {
String aDate = String.valueOf(year)+"-"+month+"-"+i;
list.add(aDate);
}