1

次の形式の文字列に時間が含まれています。

"MM/dd/yyyy hh:mm AM/PM"

24:00時間形式で時間を取得する必要があります

元:

String str = "04/30/2013 10:20PM"

私は時間を取得する必要があります22:20

4

3 に答える 3

3

You have to use SimpleDateFormat to any kind of date-time conversion.
You can try this:

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateConversion {
   public void convertDate() {
      try{
       SimpleDateFormat df = new SimpleDateFormat("HH:mm");
       SimpleDateFormat pf = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
       Date date = pf.parse("10:20PM");
       System.out.println(pf.format(date) + " = " + df.format(date));
        }catch(Exception e){
        // Do your exception handling over here.
        }
   }
}

This will solve your problem I guess.
This will give an output : 22:20

Please let me know in case of any issue.

于 2013-04-04T13:32:09.013 に答える