Java Parse Date parseDate(String line)

Here you can find the source of parseDate(String line)

Description

parse Date

License

Apache License

Declaration

public static Date parseDate(String line) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static Date parseDate(String line) {

        if (!isLogEntryStart(line)) {
            return null;
        }/*from  w  w  w  .  ja v  a2s  .  c o m*/

        SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
        try {
            return parser.parse(line.substring(0, 23));
        } catch (ParseException e) {
            return null;
        }
    }

    public static boolean isLogEntryStart(String line) {
        // TEMPORARY
        return line != null && line.length() >= 23 && line.startsWith("201") && line.charAt(4) == '-'
                && line.charAt(7) == '-' && line.charAt(10) == ' ' && line.charAt(13) == ':'
                && line.charAt(16) == ':' && line.charAt(19) == ',';
    }
}

Related

  1. parseDate(String formatPattern, String dateStr)
  2. parseDate(String formattedDate)
  3. parseDate(String gameDate)
  4. parseDate(String in)
  5. parseDate(String input)
  6. parseDate(String myDate, String pattern)
  7. parseDate(String partten, String datatime)
  8. parseDate(String representedValue)
  9. parseDate(String s)