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

后端 未结 7 1224
暗喜
暗喜 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:05

    Better Approach

    Simply Use SimpleDateFormat

    new SimpleDateFormat("MM/dd/yyyy").format(new Date(timeStampMillisInLong));
    

    Mistake in your Approach

    DAY_OF_MONTH ,MONTH, .. etc are just constant int value used by Calendar class internally

    You can get the date represented by cal by cal.get(Calendar.DATE)

提交回复
热议问题