Timestamp to string date

前端 未结 3 416
忘掉有多难
忘掉有多难 2021-02-04 01:53

I don\'t know how to transform timestamp to date. I have:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setConten         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 02:05

     public static String getTime(long timeStamp){
        try{
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(timeStamp * 1000);
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss a");
            Date date = (Date) calendar.getTime();
            return sdf.format(date);
        }catch (Exception e) {
        }
        return "";
    }
    

提交回复
热议问题