Exemple #1
0
 public static String getLocalDayOfWeek(long gmtTime) {
   // local
   Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
   cal.setTime(new Date(Util.gmtTimeToLocalTime(gmtTime) * 1000));
   String[] days = {
     "", "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"
   };
   return JLocale.getString(days[cal.get(Calendar.DAY_OF_WEEK)]);
 }
Exemple #2
0
 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;
   }
 }
Exemple #3
0
 /* Generates seconds count from 1st Jan 1970 till mentioned date */
 public static long createGmtTime(int year, int mon, int day, int hour, int min, int sec) {
   try {
     Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
     c.set(Calendar.YEAR, year);
     c.set(Calendar.MONTH, mon - 1);
     c.set(Calendar.DAY_OF_MONTH, day);
     c.set(Calendar.HOUR_OF_DAY, hour);
     c.set(Calendar.MINUTE, min);
     c.set(Calendar.SECOND, sec);
     return c.getTime().getTime() / 1000;
   } catch (Exception ignored) {
     return 0;
   }
 }
Exemple #4
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;
  }