开发者

How to Convert the Following string into Date Object?

开发者 https://www.devze.com 2023-03-09 04:42 出处:网络
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\";

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

精彩评论

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