Android Get Current timestamp?

前端 未结 12 833
灰色年华
灰色年华 2020-11-27 09:53

I want to get the current timestamp like that : 1320917972

int time = (int) (System.currentTimeMillis());
Timestamp tsTemp = new Timestamp(t         


        
12条回答
  •  北海茫月
    2020-11-27 10:47

    You can get Current timestamp in Android by trying below code

    time.setText(String.valueOf(System.currentTimeMillis()));
    

    and timeStamp to time format

    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    String dateString = formatter.format(new Date(Long.parseLong(time.getText().toString())));
    time.setText(dateString);
    

提交回复
热议问题