Android 使用 SimpleDateFormat 将字符串解析为日期时间 [英] Android parsing String to Date time with SimpleDateFormat

查看:32
本文介绍了Android 使用 SimpleDateFormat 将字符串解析为日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有字符串 11/08/2013 08:48:10

我使用 SimpleDateFormat("MM/dd/yyyy HH:mm:ss")

当我解析它时抛出异常:无法解析的日期

and when im parsing it throws an exception : unparseable date

这是怎么回事?

            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();
            }

推荐答案

它的工作尝试像这样解析你的日期..

Its working try parse your date like this..

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();
}

这篇关于Android 使用 SimpleDateFormat 将字符串解析为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆