24 hour clock not working in dateformat android

后端 未结 3 1733
暖寄归人
暖寄归人 2020-12-18 01:12

i have made an application in which i need to perform date conversion in 24 hour format. Here is my code.

GregorianCalendar c = new GregorianCalendar(Locale.         


        
相关标签:
3条回答
  • 2020-12-18 01:46
    String cdate = (String) DateFormat.format("yyyy-MM-dd kk:mm:ss", c.getTime());
    
    0 讨论(0)
  • 2020-12-18 01:56

    Try using SimpleDateFormat, a subclass of DateFormat. That might correct the problems you're having.

    e.g. to print current datetime

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_H-mm-ss",Locale.US);
    String formattedDateString = dateFormat.format(new java.util.Date());
    // result is something like "2013-02-14_18-44-15"
    
    0 讨论(0)
  • 2020-12-18 02:09

    Try this

    Long someLongDate = 240000L 
    // I was working with a Long in my own code. 
    // I'm sure you can use something like varDate.getLong()
    TextView textView = (TextView) view;                 // your view of interest
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");     
    textView.setText(sdf.format(new Date(someLongDate)));
    

    If it helped - don't forget to check my post as the answer..

    0 讨论(0)
提交回复
热议问题