import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZoneOffset; import java.util.Date; import java.util.concurrent.TimeUnit; public class QQ { public static void main(String[] args) throws ParseException { Long start = System.currentTimeMillis(); for (int i = 0; i < 100000; i++) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd 00:05:00"); SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); String dateStr = dateFormat.format(date); dateFormat2.parse(dateStr).getTime(); } System.out.println("time1 : " + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); for (int i = 0; i < 100000; i++) { Long time = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).toInstant(ZoneOffset.of("+8")).toEpochMilli(); Long time000 = time + TimeUnit.MINUTES.toMillis(5); } System.out.println("time2: " + (System.currentTimeMillis() - start)); System.out .println(LocalDateTime.of(LocalDate.now(), LocalTime.MIN).toInstant(ZoneOffset.of("+8")).toEpochMilli() + TimeUnit.MINUTES.toMillis(5)); } }
# 链接
》 https://www.cnblogs.com/peida/archive/2013/05/31/3070790.html
# 需要思考的问题:
- 线程安全问题
- 为什么创建耗时