How to get day,month,year from String date?

前端 未结 5 1203
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 06:27

I have a date on String, like this:

String date=\"25.07.2007\";

And I want to divide it to:

String day;
String month;
String yea         


        
5条回答
  •  悲&欢浪女
    2021-01-02 06:29

    public class DateTest {
    
        /**
         * @param args
         * @throws ParseException 
         */
        public static void main(String[] args) throws ParseException {
            String starDate = "7/12/1995 12:00:00 AM";
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
            String newDateStr = simpleDateFormat.format(simpleDateFormat.parse(starDate));
            String str[] = newDateStr.split("/");
            String month = str[1];
            String year = str[2];
        }
    
    }
    

提交回复
热议问题