Convert time value to format “hh:mm Am/Pm” using Android

前端 未结 10 1967
粉色の甜心
粉色の甜心 2020-11-28 13:10

I am getting date value from database like \"2013-02-27 06:06:30\" using StringTokenizer I will get time separately like below

String startTime = \"2013-02         


        
10条回答
  •  感动是毒
    2020-11-28 13:42

    First you don't need to use StringTokenizer to get the string time. Just pass your startTime like this:

    // Get date from string
    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = dateFormatter.parse(startTime);
    
    // Get time from date
    SimpleDateFormat timeFormatter = new SimpleDateFormat("h:mm a");
    String displayValue = timeFormatter.format(date);
    
    // Done!
    

提交回复
热议问题