Need get Time in a 24 hour format while adding Time

后端 未结 3 1626
北恋
北恋 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.

    0 讨论(0)
  • 2021-01-08 02:05

    You used hh in your SimpleDateFormat pattern. Thats the 12 hour format. Use kk instead, that gives you the hours of the day in a 24 hour format. See SimpleDateFormat.

    0 讨论(0)
  • 2021-01-08 02:05

    Simply create the instance of Calendar and get 24 hr time by,

    Calendar c = Calendar.getInstance();
    
    int Hr24=c.get(Calendar.HOUR_OF_DAY);
    int Min=c.get(Calendar.MINUTE);
    
    0 讨论(0)
提交回复
热议问题