开发者

How to Convert the Following string into Date Object?

I am New to Android Development.How to convert the Following string(开发者_高级运维5/31/2011) in to the Date Object I tried different ways But Couldn't get any Luck??


String dateStr = "5/31/2011";
DateFormat df = new SimpleDateFormat("M/dd/yyyy");
Date date = df.parse(dateStr);


  DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

    try {
        Date today = df.parse("5/31/2011");            
        System.out.println("Today = " + df.format(today));
    } catch (ParseException e) {
        e.printStackTrace();
    }


You can use the following

        String time1 = "5/31/2011";
        SimpleDateFormat formatter1 = new SimpleDateFormat("MM/dd/yyyy");
        Date indate1 = formatter1.parse(time1);

Thanks Deepak

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜