1、js获取年月日
var now=new Date(); var yue = (now.getMonth()+1).length > 2 ? (now.getMonth()+1):"0"+(now.getMonth()+1); var ntime = now.getFullYear().toString()+yue+now.getDate().toString();alert(ntime); //20170428 |
2、java获取年月日
①
Date d = new Date(); int year = d.getYear(); //117 int mon = d.getMonth()+1; //4 int date = d.getDate(); 转换成字符串拼接:117428 |
②
Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); system.out.println(sdf.format(d)); //20170428 |
③
Calendar now = Calendar.getInstance(); system.out.println("年月日:"+now.get(Calendar.YEAR)+(now.get(Calendar.MONTH)+1)+now.get(Calendar.DAY_OF_MONTH)); //(now.get(Calendar.MONTH)+1) //4 //2017428 |