IS中获取年月日:
javascript 自带有个对象(构造函数),Date().下面是代码:
var
oDate =
new
Date();
//实例一个时间对象;
oDate.getFullYear();
//获取系统的年;
oDate.getMonth()+1;
//获取系统月份,由于月份是从0开始计算,所以要加1
oDate.getDate();
// 获取系统日,
oDate.getHours();
//获取系统时,
oDate.getMinutes();
//分
oDate.getSeconds();
//秒
Date date=new Date();
DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time=format.format(date);
private static String firstDay;
private static String lastDay;
public static void main(String[] args) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//获取前月的第一天
Calendar cal_1=Calendar.getInstance();//获取当前日期
cal_1.add(Calendar.MONTH, -1);
cal_1.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
firstDay = format.format(cal_1.getTime());
System.out.println("-----1------firstDay:"+firstDay);
//获取前月的最后一天
Calendar cale = Calendar.getInstance();
cale.set(Calendar.DAY_OF_MONTH,0);//设置为1号,当前日期既为本月第一天
lastDay = format.format(cale.getTime());
System.out.println("-----2------lastDay:"+lastDay);
//获取当前月第一天:
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, 0);
c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
String first = format.format(c.getTime())+" 00:00:00";
System.out.println("===============first:"+first);
//获取当前月最后一天
Calendar ca = Calendar.getInstance();
ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
String last = format.format(ca.getTime());
System.out.println("===============last:"+last);
//获取当前日期
Date date=new Date();
DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time=format1.format(date);
System.out.println("===============time:"+time);
String da = time.substring(5,7);
System.out.println("===============da:"+da);
if(da.indexOf("0") != -1){
da = da.replace("0", "");
}
System.out.println("===============da1:"+da);
String time1 = "2016-11-08 00:00:00";
System.out.println("===============time1:"+time1);
da = time1.substring(5,7);
if(da.indexOf("0") != -1){
da = da.replace("0", "");
}
System.out.println("===============da1:"+da);
}