0

我正在抓取一个包含以下格式日期的网页:“2013 年 11 月 8 日”。在我返回日期后,它们被组织成一个无序的字符串数组。然后我想做的是以某种方式将这些字符串转换为简单的日期格式,如 yyyy-MM-dd,以便我可以订购它们并使用它们与日历交互?

4

4 回答 4

1

这样的事情怎么样?

private String dateLongStringConvert(String dateLongString) {

    // split long date string into string array
    String[] dateArray = dateLongString.split(" ");

    // get day of month as an integer (strip out non numeric chars)
    int dayOfMonth = Integer.parseInt(dateArray[0].replaceAll("\\D+", ""));

    // Convert month string to number
    String month = "";
    switch (dateArray[1]) {
        case "January":
            month = "01";
        case "Feburary":
            month = "02";            
        case "March":
            month = "03";            
        case "April":
            month = "04";            
        case "May":
            month = "05";            
        case "June":
            month = "06";            
        case "July":
            month = "07";            
         case "August":
            month = "08";           
          case "September":
            month = "09";          
        case "October":
            month = "10";            
        case "Novemember":
            month = "11";
        case "December":
            month = "12";                
    }
    // return formated date string
    return dateArray[2] + "-" + month + "-" + String.format("%02d", dayOfMonth);
}
于 2013-11-08T17:54:04.903 回答
1
String inputDate = "8th November 2013";
inputDate = inputDate.replaceAll("([0-9])st|nd|rd|th|\\.", "$1"); // get rid of the th.
Date date = new SimpleDateFormat("d MMM y", Locale.ENGLISH).parse(inputDate); // parse input date
String outputDate = new SimpleDateFormat("yyyy-MM-dd").format(date); // format to output date
于 2013-11-08T18:25:37.907 回答
0

to_char('YYYY/MM/DD HH24:MI:ss')

于 2013-11-08T17:39:30.043 回答
0

做这种事情的正确方法是使用像 Stanford Temporal Tagger 这样的解析器并从文本中找出日期。团队提供了一个不错的 GUI ( http://nlp.stanford.edu:8080/sutime/process ) 来评估该工具

于 2013-11-08T17:23:18.187 回答