设置好日期格式
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
拼接日期为String格式
public String combineTime(int y,int m,int d,int h,int m2,int s,int s2){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
try{
Date date=sdf.parse(y+"-"+m+"-"+d+" "+h+":"+m2+":"+s+"."+s2);
System.out.println(date.getTime());
System.out.println(sdf.format(date.getTime()));
return sdf.format(date.getTime());
}catch (Exception e){
}
return "";
}
拼接日期为Long型毫秒数
public Long combineTime2(int y,int m,int d,int h,int m2,int s,int s2){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
try{
Date date=sdf.parse(y+"-"+m+"-"+d+" "+h+":"+m2+":"+s+"."+s2);
System.out.println(date.getTime());
System.out.println(sdf.format(date.getTime()));
return date.getTime();
}catch (Exception e){
}
return 0l;
}