parse the following string to year, month, date, hourOfDay, minute, second

This question already has an answer here:

  • How to parse a date? [duplicate] 5 answers

  • You would need to use SimpleDateFormat . Have a look at the java docs. Also you would have to look at the Calendar class. Java docs are here.

    Try this -

    String str = "2000-05-12T12:00"; 
    SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
    Date d = parserSDF.parse(str);
    
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);
    
    System.out.println(cal.get(Calendar.DAY_OF_MONTH));
    System.out.println(cal.get(Calendar.MONTH)); // month in the Calendar class begins from 0
    System.out.println(cal.get(Calendar.YEAR));
    System.out.println(cal.get(Calendar.HOUR_OF_DAY));
    System.out.println(cal.get(Calendar.MINUTE));
    System.out.println(cal.get(Calendar.SECOND));
    

    try use from public SimpleDateFormat(String pattern) function.

    read this page and (http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html#parse(java.lang.String, java.text.ParsePosition) for do it!

    链接地址: http://www.djcxy.com/p/36640.html

    上一篇: SimpleDateFormat和错误的日期

    下一篇: 将以下字符串解析为year,month,date,hourOfDay,minute,second