Android Get Current timestamp?

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

    Use below method to get current time stamp. It works fine for me.

    /**
     * 
     * @return yyyy-MM-dd HH:mm:ss formate date as string
     */
    public static String getCurrentTimeStamp(){
        try {
    
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String currentDateTime = dateFormat.format(new Date()); // Find todays date
    
            return currentDateTime;
        } catch (Exception e) {
            e.printStackTrace();
    
            return null;
        }
    }
    

提交回复
热议问题