MCPcopy Create free account
hub / github.com/DeNA/PacketProxy / parse

Method parse

src/main/java/core/org/xbill/DNS/FormattedTime.java:56–77  ·  view source on GitHub ↗

Parses a formatted time string into a Date. @param s The string, in the form YYYYMMDDHHMMSS. @return The Date object. @throws TextParseExcetption The string was invalid.

(String s)

Source from the content-addressed store, hash-verified

54 * @throws TextParseExcetption The string was invalid.
55 */
56public static Date
57parse(String s) throws TextParseException {
58 if (s.length() != 14) {
59 throw new TextParseException("Invalid time encoding: " + s);
60 }
61
62 Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
63 c.clear();
64 try {
65 int year = Integer.parseInt(s.substring(0, 4));
66 int month = Integer.parseInt(s.substring(4, 6)) - 1;
67 int date = Integer.parseInt(s.substring(6, 8));
68 int hour = Integer.parseInt(s.substring(8, 10));
69 int minute = Integer.parseInt(s.substring(10, 12));
70 int second = Integer.parseInt(s.substring(12, 14));
71 c.set(year, month, date, hour, minute, second);
72 }
73 catch (NumberFormatException e) {
74 throw new TextParseException("Invalid time encoding: " + s);
75 }
76 return c.getTime();
77}
78
79}

Callers 1

rdataFromStringMethod · 0.95

Calls 3

lengthMethod · 0.80
clearMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected