Parse Date String to Some Java Object

前端 未结 6 2194
太阳男子
太阳男子 2020-11-28 15:41

I am working in a project that reads files and processes data. There I got to work with dates for example:

  1. 2012-01-10 23:13:26
  2. January 13, 2012
  3. <
6条回答
  •  独厮守ぢ
    2020-11-28 16:15

    SimpleDateFormat will parse dates into Java Date objects:

    http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html

    SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); // first example
    SimpleDateFormat format2 = new SimpleDateFormat("MMMMM dd,yyyy"); // second example
    
    Date d1 = format1.parse( dateStr1 );
    Date d2 = format2.parse( dateStr2 );
    

提交回复
热议问题