Need get Time in a 24 hour format while adding Time

后端 未结 3 1630
北恋
北恋 2021-01-08 01:05

I had written a function for Adding time as given below

private void Delay15Minute() {
        String pkManifest = manifest.pkManifestNo;
        manifest_he         


        
3条回答
  •  一向
    一向 (楼主)
    2021-01-08 01:46

    Use this code

    long date = System.currentTimeMillis();
    
    SimpleDateFormat date1 = new SimpleDateFormat("dd-MM-yyyy"); // for current date
    SimpleDateFormat time1 = new SimpleDateFormat("kk:mm:ss");  // for 24 hour time
    SimpleDateFormat time2 = new SimpleDateFormat("hh:mm:ss");  // for 12 hour time 
    
    String dateString = date1.format(date);    //This will return current date in 31-12-2018 format
    String timeString1 = time1.format(date);  //This will return current time in 24 Hour format
    String timeString2 = time2.format(date);  //This will return current time in 12 Hour format
    
    Log.e("TAG_1", "24 hour Time - " + timeString1);
    Log.e("TAG_1", "24 hour Time - " + timeString1);
    Log.e("TAG_1", "dd-MM-yyyy Date format - " + dateString);
    

    than open your logcat to check result.

提交回复
热议问题