Timestamp to string date

前端 未结 3 537
忘掉有多难
忘掉有多难 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:19

    try this if you're sticking with "1350574775" format which is in seconds:

    private void onCreate(Bundle bundle){
        ....
        String S = "1350574775";
    
        //convert unix epoch timestamp (seconds) to milliseconds
        long timestamp = Long.parseLong(s) * 1000L; 
        czas.setText(getDate(timestamp ));  
    }
    
    
    
    private String getDate(long timeStamp){
    
        try{
            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
            Date netDate = (new Date(timeStamp));
            return sdf.format(netDate);
        }
        catch(Exception ex){
            return "xx";
        }
    } 
    

提交回复
热议问题