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

后端 未结 7 1208
暗喜
暗喜 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 11:53

    TimeZone utc = TimeZone.getTimeZone("UTC"); // avoiding local time zone overhead
    final Calendar cal = new GregorianCalendar(utc);
    
    // always use GregorianCalendar explicitly if you don't want be suprised with
    // Japanese Imperial Calendar or something
    
    cal.setTimeInMillis(1306249409L*1000); // input need to be in miliseconds
    
    Log.d("Date--",""+cal.get(Calendar.DAY_OF_MONTH));
    
    Log.d("Month--",""+cal.get(Calendar.MONTH) + 1); // it starts from zero, add 1
    
    Log.d("Year--",""+cal.get(Calendar.YEAR));
    

提交回复
热议问题