Android Get Current timestamp?

前端 未结 12 876
灰色年华
灰色年华 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:48

    It's simple use:

    long millis = new Date().getTime();
    

    if you want it in particular format then you need Formatter like below

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String millisInString  = dateFormat.format(new Date());
    

提交回复
热议问题