Changeset 8574 in josm for trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java
- Timestamp:
- 2015-07-05T22:14:49+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java
r8565 r8574 66 66 */ 67 67 public static synchronized Date fromString(String str) { 68 return new Date(tsFromString(str)); 69 } 70 71 /** 72 * Parses XML date quickly, regardless of current locale. 73 * @param str The XML date as string 74 * @return The date in milliseconds since epoch 75 */ 76 public static synchronized long tsFromString(String str) { 68 77 // "2007-07-25T09:26:24{Z|{+|-}01:00}" 69 78 if (checkLayout(str, "xxxx-xx-xxTxx:xx:xxZ") || … … 83 92 int plusHr = parsePart2(str, 20); 84 93 int mul = str.charAt(19) == '+' ? -3600000 : 3600000; 85 calendar.setTimeInMillis(calendar.getTimeInMillis()+plusHr*mul);94 return calendar.getTimeInMillis()+plusHr*mul; 86 95 } 87 96 88 return calendar.getTime ();97 return calendar.getTimeInMillis(); 89 98 } else if (checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxxZ") || 90 99 checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx") || … … 99 108 parsePart2(str, 17)); 100 109 long millis = parsePart3(str, 20); 101 if (str.length() == 29) 110 if (str.length() == 29){ 102 111 millis += parsePart2(str, 24) * (str.charAt(23) == '+' ? -3600000 : 3600000); 103 calendar.setTimeInMillis(calendar.getTimeInMillis()+millis);104 105 return calendar.getTime ();112 } 113 114 return calendar.getTimeInMillis() + millis; 106 115 } else { 107 116 // example date format "18-AUG-08 13:33:03" … … 109 118 Date d = f.parse(str, new ParsePosition(0)); 110 119 if (d != null) 111 return d ;120 return d.getTime(); 112 121 } 113 122 114 123 try { 115 return XML_DATE.newXMLGregorianCalendar(str).toGregorianCalendar().getTime ();124 return XML_DATE.newXMLGregorianCalendar(str).toGregorianCalendar().getTimeInMillis(); 116 125 } catch (Exception ex) { 117 return new Date();126 return System.currentTimeMillis(); 118 127 } 119 128 }
Note:
See TracChangeset
for help on using the changeset viewer.