SimpleDateFormat 格式化到毫秒
在开发时,某些场景是需要格式化时间到毫秒等精度,比如生成文件名字等,实现代码如下:
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
System.out.println("======"+sdf.format(new Date()));
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmssSSSXXX");
System.out.println("======"+sdf1.format(new Date()));
SimpleDateFormat sdf11 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSSSSS");
System.out.println("======"+sdf11.format(new Date()));
SimpleDateFormat sdf111 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSSSSSXXX");
System.out.println("======"+sdf111.format(new Date()));
System.out.println("======"+System.currentTimeMillis());
输出结果:
======20200404011237062
======20200404011237063+08:00
======20200404011237000000063
======20200404011237000000064+08:00
======1585933957064