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

后端 未结 7 1164
暗喜
暗喜 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:15

    use String.format which is able to convert long (milliseconds) to date/time string in different formats:

        String str;
        long time = 1306249409 * 1000L;  // milliseconds
        str = String.format("%1$tm/%1$td/%1$ty", time);  // 05/24/11
        str = String.format("%tF", time);                // 2011-05-24 (ISO 8601)
        str = String.format("Date--%td", time);          // Date--24
        str = String.format("Month--%tm", time);         // Month--05
        str = String.format("Year--%ty", time);          // Year--11
    

    documentation: format string.

    0 讨论(0)
提交回复
热议问题