Esempio n. 1
0
  static Date parseDate(String s) {
    Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));

    int year = Integer.parseInt(s.substring(0, 4));
    int month = Integer.parseInt(s.substring(4, 6)) - 1;
    int date = Integer.parseInt(s.substring(6, 8));
    int hour = Integer.parseInt(s.substring(8, 10));
    int minute = Integer.parseInt(s.substring(10, 12));
    int second = Integer.parseInt(s.substring(12, 14));
    c.set(year, month, date, hour, minute, second);

    return c.getTime();
  }
Esempio n. 2
0
  static String formatDate(Date d) {
    Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    StringBuffer sb = new StringBuffer();
    NumberFormat w4 = new DecimalFormat();
    w4.setMinimumIntegerDigits(4);
    w4.setGroupingUsed(false);
    NumberFormat w2 = new DecimalFormat();
    w2.setMinimumIntegerDigits(2);

    c.setTime(d);
    sb.append(w4.format(c.get(c.YEAR)));
    sb.append(w2.format(c.get(c.MONTH) + 1));
    sb.append(w2.format(c.get(c.DAY_OF_MONTH)));
    sb.append(w2.format(c.get(c.HOUR_OF_DAY)));
    sb.append(w2.format(c.get(c.MINUTE)));
    sb.append(w2.format(c.get(c.SECOND)));
    return sb.toString();
  }