java获取当前时间精确到毫秒
new SimpleDateFormat("yyyyMMddHHmmssSSS") .format(new Date() );
方法2:
Calendar Cld = Calendar.getInstance();
int YY = Cld.get(Calendar.YEAR) ;
int MM = Cld.get(Calendar.MONTH)+1;
int DD = Cld.get(Calendar.DATE);
int HH = Cld.get(Calendar.HOUR_OF_DAY);
int mm = Cld.get(Calendar.MINUTE);
int SS = Cld.get(Calendar.SECOND);
int MI = Cld.get(Calendar.MILLISECOND);
String curTime = YY + MM + DD + HH + mm + SS + MI;
Calendar cal = Calendar.getInstance();
java.util.Date date = cal.getTime();
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMMddhhmmssSSS");
String myTime = sdFormat.format(currentTime);
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
System.out.println(df.format(new Date()));
}
}
System.out.println(currentDate);
new Date()