private static int[] getVersionDate(String str) { String[] svers = Util.explode(str, '.'); int[] ivers = new int[3]; for (int num = 0; num < ivers.length; num++) { ivers[num] = Util.strToIntDef(num < svers.length ? svers[num] : "", 0); } return ivers; }
public static long createLocalDate(String date) { try { date = date.replace('.', ' ').replace(':', ' '); String[] values = Util.explode(date, ' '); Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); c.set(Calendar.YEAR, Util.strToIntDef(values[2], 0)); c.set(Calendar.MONTH, Util.strToIntDef(values[1], 0) - 1); c.set(Calendar.DAY_OF_MONTH, Util.strToIntDef(values[0], 0)); c.set(Calendar.HOUR_OF_DAY, Util.strToIntDef(values[3], 0)); c.set(Calendar.MINUTE, Util.strToIntDef(values[4], 0)); c.set(Calendar.SECOND, 0); return localTimeToGmtTime(c.getTime().getTime() / 1000); } catch (Exception ignored) { return 0; } }
public static long createGmtDate(String sdate) { Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); try { sdate = sdate.trim(); int[] ofs = sdate.endsWith("Z") ? ofsFieldsB : ofsFieldsA; long result; if (Character.isDigit(sdate.charAt(0))) { int fieldLength = 4; // yearlen for (int i = 0; i < calFields.length; ++i) { int begIndex = ofs[i]; int field = strToIntDef(sdate.substring(begIndex, begIndex + fieldLength), 0); if (1 == i) { field += Calendar.JANUARY - 1; } fieldLength = 2; c.set(calFields[i], field); } result = Math.max(0, c.getTime().getTime() / 1000); } else { String[] rfcDate = Util.explode(sdate, ' '); c.set(Calendar.YEAR, strToIntDef(rfcDate[3], 0)); for (int i = 0; i < months.length; ++i) { if (months[i].equals(rfcDate[2])) { c.set(Calendar.MONTH, i); break; } } c.set(Calendar.DAY_OF_MONTH, strToIntDef(rfcDate[1], 0)); c.set(Calendar.HOUR_OF_DAY, strToIntDef(rfcDate[4].substring(0, 2), 0)); c.set(Calendar.MINUTE, strToIntDef(rfcDate[4].substring(3, 5), 0)); c.set(Calendar.SECOND, strToIntDef(rfcDate[4].substring(6), 0)); long delta = strToIntDef(rfcDate[5].substring(1, 3), 0) * 60 * 60 + strToIntDef(rfcDate[5].substring(3, 5), 0) * 60; if ('+' == rfcDate[5].charAt(0)) { delta = -delta; } result = Math.max(0, c.getTime().getTime() / 1000 + delta); } return result; } catch (Exception ignored) { } return 0; }