Java – use simpledateformat to parse strings to date and time

I have string 11 / 08 / 2013 08:48:10

I use simpledateformat ("mm / DD / yyyy HH: mm: SS")

When I parse it, I throw an exception: an unresolved date

What's wrong with it?

String result = han.ExecuteUrl("http://"+han.IP+":8015/api/Values/GetLastChange"); 
            Log.d("Dal","result date time "+result); #result is 11/08/2013 08:48:10
            SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

            Date convertedDate = new Date();
            try
            {

                convertedDate = dateFormat.parse(result);
            }
            catch (ParseException e)
            {
                e.printStackTrace();
            }

Solution

Its job is to try to parse your date

String dtStart = "11/08/2013 08:48:10";
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
try {
    date = format.parse(dtStart);
    System.out.println("Date ->" + date);
} catch (ParseException e) {
    e.printStackTrace();
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>