Note that there are some explanatory texts on larger screens.

plurals
  1. PODistinguishing and Parsing Dates in Java
    text
    copied!<p>i know this topic isn't new, though i have to dig it up again. I already searched the Web numerous times (including some Threads here on stackoverflow) but haven't found a satisfying answer so far. </p> <p>(Amongst others I checked <a href="https://stackoverflow.com/questions/1552643/parsing-ambiguous-dates-in-java">Parsing Ambiguous Dates in Java</a> and <a href="http://www.coderanch.com/t/375367/java/java/Handling-Multiple-Date-Formats-Elegantly" rel="nofollow noreferrer">http://www.coderanch.com/t/375367/java/java/Handling-Multiple-Date-Formats-Elegantly</a></p> <p>I am currently writing a Dateparser in Java, which takes a date and generates a format-String which can be used by SimpleDateFormat for parsing the date.</p> <p>The dates are parsed via regex (yes, it's an ugly one xD) from Logfiles (IBM Websphere, Tomcat, Microsoft Exchange, ....). Because we have customers in (at least 2) different Locales, there is no way to simply "throw" the String against the parse-method of SimpleDateFormat and expect it to work properly. </p> <p>Furthermore, there is the problem with the position of day and month (i.e. formats "dd/MM/yyyy" or "MM/dd/yyyy") which cannot be solved if i don't have at least two datasets where the day-digit has changed.. </p> <p>So my current approach would be storing the dateformats for a specific software installed at a specific customer's systems in a database (mysql / xml / ... ) and forcing the user to at least specify customername and softwarename so there is enough context to break down the amount of possibilites the format may be given in. </p> <p>This "subset" then would be used to try to parse the logfiles of the specified software. (The subset is stored in a HashMap in a HashMap in the form HashMap> map; The Integer-Key is the length of the formatstring and the String Key of the second Hashmap specifies a datesignature only containing the separating characters. (i.e. ".. ::." for a date with format "dd.MM.yyyy 11:11:11.111") </p> <p>I also take into account the value of the digits, i.e. a digit > 12 has to be a day because there is no 13th month. But this only works reliably for Date-Strings later than the 12th of a month.. </p> <p>Is there any chance to avoid implementing prior knowledge about the environment out of which the logfile came, thus enabling the parser to reliably parse one date without having to refer a second datestring for comparison? </p> <p>I'm stuck on that for almost 3 months now -.- </p> <p>Any suggestions would be very welcome =) </p> <p><strong>Edit:</strong></p> <p>Okay guys this thread can be closed. I now came up with a different solution for my specific problem. For those who are interested: I am writing a Logreader in Java. As we have regular maintenance I have to read many logfiles. But it's not just the plain text information that's written in the file. Imagine a server just having crashed, it's sunday night and the next person to notice is the head of the IT dpt of the customer. Then on the following day I have to to maintenance and check the logfiles. Judging by content, everything seemed okay, nothing unusual. Half an hour after sending the maintenance report I receive a mail with the above mentioned head of it dpt ranting, that the server had crashed and it seemed to go unnoticed. </p> <p>The point is, you can't keep track over content and the timestamps for logfiles with several thousand lines. So i developed a component which reads a logfile and calculates the time between two different log-entrys. Each logline got parsed into a java.util.Date to later get the Date as Timestamp for high resolution regarding the log-intervals. The differences i then threw onto a linegraph, which makes longer timeouts between two loglines visible as a big spike relating to the rest of the file. </p> <p>My solution now will be to completely throw away the date-half of the String and insert a dummy-Date with a predefined format. The date only has to change if the Hour and minute approach 23:59. The original date later is presented on the graph with the "fake-data" lying beneath.</p> <p>I thank all of you for your suggestions and feedback =) (And I hope my English has been understandable so far ;) )</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload