How to convert Gregorian string to Gregorian Calendar?

后端 未结 3 1134
醉话见心
醉话见心 2020-12-19 22:51

I have to compute something based on the Calendar\'s date, but I am receiving the complete Gregorian Calendar\'s String value.

Eg i/p received {may be - \"new

3条回答
  •  误落风尘
    2020-12-19 23:20

    GregorianCalendar g=new GregorianCalendar(1975, 5, 7);
        Date d=g.getTime();
        System.out.println(g.toString());
        SimpleDateFormat formatter=new SimpleDateFormat("yyyy MM dd"); 
        System.out.println(formatter.format(d));
    

    This is way to grab date from GregorianCalendar. i wish this will help to you

    Adding more to this, you can retrieve any information you want using the format. It's just a matter of providing the correct format.

    Ex:
    Adding z or Z provides you with the timezone information

    "yyyy MM dd z" - 2014 10 12 PDT
    "yyyy MM dd Z" - 2014 10 12 -0700
    

    Adding a 'T' would result in something like this:

    "yyyy-MM-dd'T'HH:mm:ss.sssZ" - 2014-10-12T14:23:51.890+0530
    

    In this HH represents hours in 24 hour format mm minutes ss seconds sss milliseconds.

提交回复
热议问题