How can I get Date in MM/DD/YY format from Timestamp

后端 未结 7 1207
暗喜
暗喜 2020-12-16 11:27

I want to get the Date in MM/DD/YY format from a timestamp.

I have used the below method but it does not gives proper output

final Calen         


        
7条回答
  •  天命终不由人
    2020-12-16 12:13

    Java uses the number of milliseconds since 1st January 1970 to represent times. If you compute the time represented by 1306249409 milliseconds, you'll discover that it's only 362 days, so your assumptions are wrong.

    Moreover, cal.DAY_OF_MONTH holds a constant. Use cal.get(Calendar.DAY_OF_MONTH) to get the day of month (same for other parts of the date).

提交回复
热议问题