Difference between System.currentTimeMillis() and Date getTime()?

前端 未结 3 2122
故里飘歌
故里飘歌 2021-02-14 03:08

I was hoping to squeeze a tiny performance gain out of many calls to a function that returns a timestamp. The function looks like this:

public static long get_n         


        
3条回答
  •  礼貌的吻别
    2021-02-14 03:54

    No difference, except for the very slight lag caused by allocating a Date object.

    From the javadoc the the default constructor of Date:

    Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.

    A Date is just a thin wrapper around the epoch milliseconds, without any concept of timezones. Only when rendered to a String is timezone considered, but that is handled by the Locale class.

提交回复
热议问题