Beispiel #1
1
  public int daysBetween(Calendar day1, Calendar day2) {
    Calendar dayOne = (Calendar) day1.clone(), dayTwo = (Calendar) day2.clone();

    if (dayOne.get(Calendar.YEAR) == dayTwo.get(Calendar.YEAR)) {
      return Math.abs(dayOne.get(Calendar.DAY_OF_YEAR) - dayTwo.get(Calendar.DAY_OF_YEAR));
    } else {
      if (dayTwo.get(Calendar.YEAR) > dayOne.get(Calendar.YEAR)) {
        // swap them
        Calendar temp = dayOne;
        dayOne = dayTwo;
        dayTwo = temp;
      }
      int extraDays = 0;

      int dayOneOriginalYearDays = dayOne.get(Calendar.DAY_OF_YEAR);

      while (dayOne.get(Calendar.YEAR) > dayTwo.get(Calendar.YEAR)) {
        dayOne.add(Calendar.YEAR, -1);
        // getActualMaximum() important for leap years
        extraDays += dayOne.getActualMaximum(Calendar.DAY_OF_YEAR);
      }

      return extraDays - dayTwo.get(Calendar.DAY_OF_YEAR) + dayOneOriginalYearDays;
    }
  }
 private void updateTime() {
   Calendar cal = GregorianCalendar.getInstance();
   cal.setTime(new Date());
   mTvCurrentTime.setText(
       String.format("%02d:%02d", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE)));
   mHandler.sendEmptyMessageDelayed(MSG_UPDATE_TIME, 5000);
 }
Beispiel #3
1
 public static Date getFirstDayOfMonth(Calendar c) {
   int year = c.get(Calendar.YEAR);
   int month = c.get(Calendar.MONTH);
   int day = 1;
   c.set(year, month, day, 0, 0, 0);
   return c.getTime();
 }
  private static boolean keepCurrent(Calendar asOfDate) {
    boolean keepCurrent = false;

    int monthNow = asOfDate.get(Calendar.MONTH);

    // March, June, September, and December are expiration months
    boolean isExpirationMonth = ((monthNow + 1) % 3 == 0);

    if (isExpirationMonth) {
      Calendar volumeShiftDate = (Calendar) asOfDate.clone();

      // Find first Friday
      volumeShiftDate.set(Calendar.DAY_OF_MONTH, 1);
      while (volumeShiftDate.get(Calendar.DAY_OF_WEEK) != Calendar.FRIDAY) {
        volumeShiftDate.add(Calendar.DAY_OF_MONTH, 1);
      }

      // Shift to third Friday
      volumeShiftDate.add(Calendar.WEEK_OF_MONTH, 2);

      // Finally, find the day before second Friday
      volumeShiftDate.add(Calendar.DAY_OF_MONTH, -8);

      if (asOfDate.before(volumeShiftDate)) {
        keepCurrent = true;
      }
    }

    return keepCurrent;
  }
  /** Initialize this creature. */
  public void initCreature() {
    if (this.worldObj.provider instanceof WorldProviderHell && this.getRNG().nextInt(5) > 0) {
      this.tasks.addTask(4, this.field_85038_e);
      this.setSkeletonType(1);
      this.setCurrentItemOrArmor(0, new ItemStack(Item.swordStone));
    } else {
      this.tasks.addTask(4, this.field_85037_d);
      this.func_82164_bB();
      this.func_82162_bC();
    }

    if (this.rand.nextFloat() >= field_82181_as[this.worldObj.difficultySetting]) {;
    }

    this.canPickUpLoot = true;

    if (this.getCurrentItemOrArmor(4) == null) {
      Calendar var1 = this.worldObj.getCurrentDate();

      if (var1.get(2) + 1 == 10 && var1.get(5) == 31 && this.rand.nextFloat() < 0.25F) {
        this.setCurrentItemOrArmor(
            4, new ItemStack(this.rand.nextFloat() < 0.1F ? Block.pumpkinLantern : Block.pumpkin));
        this.equipmentDropChances[4] = 0.0F;
      }
    }
  }
  @RequestMapping(
      value = "/admin/search-reindex",
      method = RequestMethod.POST,
      params = "action=current")
  public ModelAndView reindexCurrentMonth(ServletRequest request) throws Exception {
    Template tmpl = Template.getTemplate(request);

    Connection db = LorDataSource.getConnection();

    try {
      if (!tmpl.isSessionAuthorized()) {
        throw new AccessViolationException("Not authorized");
      }

      tmpl.getCurrentUser().checkDelete();

      Calendar current = Calendar.getInstance();

      for (int i = 0; i < 3; i++) {
        searchQueueSender.updateMonth(current.get(Calendar.YEAR), current.get(Calendar.MONTH) + 1);
        current.add(Calendar.MONTH, -1);
      }

      return new ModelAndView("action-done", "message", "Scheduled reindex last 3 month");
    } finally {
      JdbcUtils.closeConnection(db);
    }
  }
 public int obtenerDiasHabiles(Date fecha, Date fecha2) {
   Calendar calendario = Calendar.getInstance();
   calendario.setTimeZone(TimeZone.getTimeZone("GMT-4:00"));
   calendario.setTime(fecha2);
   calendario.add(Calendar.DAY_OF_YEAR, +1);
   calendario.set(Calendar.HOUR, 0);
   calendario.set(Calendar.HOUR_OF_DAY, 0);
   calendario.set(Calendar.SECOND, 0);
   calendario.set(Calendar.MILLISECOND, 0);
   calendario.set(Calendar.MINUTE, 0);
   fecha2 = calendario.getTime();
   calendario.setTime(fecha);
   String fija = formatoFecha.format(fecha2);
   String hoy = "";
   int contador = 0;
   do {
     calendario.setTime(fecha);
     if (calendario.get(Calendar.DAY_OF_WEEK) != 1 && calendario.get(Calendar.DAY_OF_WEEK) != 7)
       contador++;
     calendario.add(Calendar.DAY_OF_YEAR, +1);
     fecha = calendario.getTime();
     hoy = formatoFecha.format(fecha);
   } while (!hoy.equals(fija));
   return contador;
 }
  public String getDisplayDateString() {
    Calendar now = Calendar.getInstance();
    Calendar posted = Calendar.getInstance();
    posted.setTime(date);

    int nowDay = now.get(Calendar.DAY_OF_YEAR);
    int postedDay = posted.get(Calendar.DAY_OF_YEAR);

    int diff = nowDay - postedDay;

    StringBuilder sb = new StringBuilder();
    if (diff == 0) {
      sb.append("Posted today");
    } else if (diff == 1) {
      sb.append("Posted yesterday");
    } else {
      sb.append("Posted ");
      sb.append(diff);
      sb.append(" days ago");
    }
    sb.append(" (");
    sb.append(DISPLAY_DATE_FORMAT.format(date));
    sb.append(")");

    return sb.toString();
  }
 private boolean isValid(String dateString, String pattern) {
   boolean valid = true;
   Date date;
   SimpleDateFormat sdf = new SimpleDateFormat(pattern);
   sdf.setLenient(false);
   try {
     dateString = dateString.trim();
     date = sdf.parse(dateString);
     Calendar calendar = Calendar.getInstance();
     calendar.setTime(date);
     int year = calendar.get(Calendar.YEAR);
     int era = calendar.get(Calendar.ERA);
     if (era == GregorianCalendar.AD) {
       if (year > 9999) {
         valid = false;
       }
     }
     //   System.out.println("pattern is "+ pattern);
     //   System.out.println("Year is "+year);
     //   System.out.println("Calendar date is "+date.toString());
     //   System.out.println("Era is "+calendar.get(Calendar.ERA));
   } catch (ParseException e) {
     valid = false;
   }
   if (dateString.length() > pattern.length()) {
     valid = false;
   }
   return valid;
 }
Beispiel #10
0
 /**
  * True if the time is this year.
  *
  * @param time the time
  */
 private static boolean isThisYear(long time) {
   Calendar now = Calendar.getInstance();
   Calendar calendar = Calendar.getInstance();
   now.setTimeInMillis(System.currentTimeMillis());
   calendar.setTimeInMillis(time);
   return now.get(Calendar.YEAR) == calendar.get(Calendar.YEAR);
 }
  @Override
  public List<TimeSlot> findByDate(Date date) {
    List<TimeSlot> timeSlots = Lists.newArrayList();
    SqlApi sqlApi = SqlApi.create();

    Calendar calendar = GregorianCalendar.getInstance();
    calendar.setTime(date);
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    boolean isOdd = calendar.get(Calendar.WEEK_OF_YEAR) % 2 == 1;

    try {
      List<CallableStatement> stmts =
          sqlApi.prepareScript(
              "SELECT * FROM TimeSlot WHERE day=? AND is_odd=? ORDER BY start_min");
      stmts.get(0).setInt(1, day);
      stmts.get(0).setInt(2, (isOdd) ? 1 : 2);

      ResultSet rs = stmts.get(0).executeQuery();
      fetchTimeSlots(rs, timeSlots);
      return timeSlots;

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      sqlApi.dispose();
    }

    return null;
  }
  /**
   * For the contracts whose volume shifts from the front contract to the back contract on the day
   * preceding the 2nd Friday of expiration month of the front contract.
   */
  public static String getMostLiquid(Calendar asOfDate) {

    int monthNow = asOfDate.get(Calendar.MONTH);
    int yearNow = asOfDate.get(Calendar.YEAR);
    int mostLiquidYear = yearNow;

    int mostLiquidMonth = frontMonths.get(monthNow);

    // special case with December
    if (monthNow == Calendar.DECEMBER) {
      mostLiquidYear = yearNow + 1;
    }

    if (keepCurrent(asOfDate)) {
      mostLiquidMonth = monthNow;
      mostLiquidYear = yearNow;
    }

    Calendar mostLiquidDate = Calendar.getInstance();
    mostLiquidDate.set(Calendar.DAY_OF_MONTH, 1);
    mostLiquidDate.set(Calendar.MONTH, mostLiquidMonth);
    mostLiquidDate.set(Calendar.YEAR, mostLiquidYear);

    SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
    return df.format(mostLiquidDate.getTime());
  }
  /**
   * This method is not thread safe. It has been modified from the original to not rely on global
   * time state. If a timestamp is in the future we return it as an absolute date string. Within the
   * same second we return 0s
   *
   * @param res resource
   * @param currentTimeMillis timestamp for offset
   * @param timestamp timestamp
   * @return the relative time string
   */
  static String getRelativeTimeString(Resources res, long currentTimeMillis, long timestamp) {
    final long diff = currentTimeMillis - timestamp;
    if (diff >= 0) {
      if (diff < DateUtils.MINUTE_IN_MILLIS) { // Less than a minute ago
        final int secs = (int) (diff / 1000);
        return res.getQuantityString(R.plurals.tw__time_secs, secs, secs);
      } else if (diff < DateUtils.HOUR_IN_MILLIS) { // Less than an hour ago
        final int mins = (int) (diff / DateUtils.MINUTE_IN_MILLIS);
        return res.getQuantityString(R.plurals.tw__time_mins, mins, mins);
      } else if (diff < DateUtils.DAY_IN_MILLIS) { // Less than a day ago
        final int hours = (int) (diff / DateUtils.HOUR_IN_MILLIS);
        return res.getQuantityString(R.plurals.tw__time_hours, hours, hours);
      } else {
        final Calendar now = Calendar.getInstance();
        now.setTimeInMillis(currentTimeMillis);
        final Calendar c = Calendar.getInstance();
        c.setTimeInMillis(timestamp);
        final Date d = new Date(timestamp);

        if (now.get(Calendar.YEAR) == c.get(Calendar.YEAR)) {
          // Same year
          RELATIVE_DATE_FORMAT.applyPattern(res.getString(R.string.tw__relative_date_format_short));
        } else {
          // Outside of our year
          RELATIVE_DATE_FORMAT.applyPattern(res.getString(R.string.tw__relative_date_format_long));
        }
        return RELATIVE_DATE_FORMAT.format(d);
      }
    }
    RELATIVE_DATE_FORMAT.applyPattern(res.getString(R.string.tw__relative_date_format_long));
    return RELATIVE_DATE_FORMAT.format(new Date(timestamp));
  }
Beispiel #14
0
  public static String formatDateOnline(long date) {
    Calendar rightNow = Calendar.getInstance();
    int day = rightNow.get(Calendar.DAY_OF_YEAR);
    int year = rightNow.get(Calendar.YEAR);
    rightNow.setTimeInMillis(date * 1000);
    int dateDay = rightNow.get(Calendar.DAY_OF_YEAR);
    int dateYear = rightNow.get(Calendar.YEAR);

    if (dateDay == day && year == dateYear) {
      return String.format(
          "%s %s",
          ApplicationLoader.applicationContext.getResources().getString(R.string.TodayAt),
          formatterDay.format(new Date(date * 1000)));
    } else if (dateDay + 1 == day && year == dateYear) {
      return String.format(
          "%s %s",
          ApplicationLoader.applicationContext.getResources().getString(R.string.YesterdayAt),
          formatterDay.format(new Date(date * 1000)));
    } else if (year == dateYear) {
      return String.format(
          "%s %s %s",
          formatterMonth.format(new Date(date * 1000)),
          ApplicationLoader.applicationContext.getResources().getString(R.string.OtherAt),
          formatterDay.format(new Date(date * 1000)));
    } else {
      return String.format(
          "%s %s %s",
          formatterYear.format(new Date(date * 1000)),
          ApplicationLoader.applicationContext.getResources().getString(R.string.OtherAt),
          formatterDay.format(new Date(date * 1000)));
    }
  }
  public Prestamo crearPrestamo(
      Cliente cliente, String comentario, Date fecha, FormaPago formaPago, double monto, float tasa)
      throws PrestamoException {
    if (monto < 0) throw new PrestamoException("Valor del 'monto' es menor que cero (0)");

    Prestamo prestamo = new Prestamo();
    prestamo.setCliente(cliente);
    prestamo.setComentario(comentario);

    Calendar c = Calendar.getInstance();
    // hora
    int hora = c.get(Calendar.HOUR_OF_DAY);
    int minuto = c.get(Calendar.MINUTE);

    c.setTime(fecha);
    c.set(Calendar.HOUR_OF_DAY, hora);
    c.set(Calendar.MINUTE, minuto);

    prestamo.setFecha(c.getTime());
    prestamo.setFormaPago(formaPago);
    prestamo.setMonto(monto);
    prestamo.setTasa(tasa);

    persist(prestamo);

    if (prestamo.getId() != null) return prestamo;
    return null;
  }
 private void timePick() {
   Calendar calendar = Calendar.getInstance();
   final int hour = calendar.get(Calendar.HOUR_OF_DAY);
   int minute = calendar.get(Calendar.MINUTE);
   TimePickerDialog timePickerDialog =
       new TimePickerDialog(
           BaseInfoPostActivity.this,
           new TimePickerDialog.OnTimeSetListener() {
             @Override
             public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
               String newHour;
               String newMinute;
               if (hourOfDay < 10) {
                 newHour = "0" + hourOfDay;
               } else {
                 newHour = String.valueOf(hourOfDay);
               }
               if (minute < 10) {
                 newMinute = "0" + minute;
               } else {
                 newMinute = String.valueOf(minute);
               }
               String time = newHour + ":" + newMinute;
               mBtnTimePicker.setText(time);
               host.setTime(time);
             }
           },
           hour,
           minute,
           true);
   timePickerDialog.show();
 }
 /**
  * JavaSource_Calendar: The default constructor uses the current Gregorian date to initialize the
  * other private memebers of the class (Iranian and Julian dates).
  */
 public CalendarTool() {
   Calendar calendar = new GregorianCalendar();
   setGregorianDate(
       calendar.get(Calendar.YEAR),
       calendar.get(Calendar.MONTH) + 1,
       calendar.get(Calendar.DAY_OF_MONTH));
 }
Beispiel #18
0
  /** Make an update for the daily/weekly/last kill & ap counts */
  public void doUpdate() {
    boolean needUpdate = false;
    Calendar lastCal = Calendar.getInstance();
    lastCal.setTimeInMillis(lastUpdate);

    Calendar curCal = Calendar.getInstance();
    curCal.setTimeInMillis(System.currentTimeMillis());

    // Checking the day - month & year are checked to prevent if a player come back after 1 month,
    // the same day
    if (lastCal.get(Calendar.DAY_OF_MONTH) != curCal.get(Calendar.DAY_OF_MONTH)
        || lastCal.get(Calendar.MONTH) != curCal.get(Calendar.MONTH)
        || lastCal.get(Calendar.YEAR) != curCal.get(Calendar.YEAR)) {
      this.dailyAP = 0;
      this.dailyKill = 0;
      needUpdate = true;
    }

    // Checking the week - year is checked to prevent if a player come back after 1 year, the same
    // week
    if (lastCal.get(Calendar.WEEK_OF_YEAR) != curCal.get(Calendar.WEEK_OF_YEAR)
        || lastCal.get(Calendar.YEAR) != curCal.get(Calendar.YEAR)) {
      this.lastKill = this.weeklyKill;
      this.lastAP = this.weeklyAP;
      this.weeklyKill = 0;
      this.weeklyAP = 0;
      needUpdate = true;
    }

    // Finally, update the the last update
    this.lastUpdate = System.currentTimeMillis();

    if (needUpdate) setPersistentState(PersistentState.UPDATE_REQUIRED);
  }
Beispiel #19
0
 private void trim(Calendar calendar) {
   int hours = calendar.get(Calendar.HOUR_OF_DAY);
   int minutes = calendar.get(Calendar.MINUTE);
   calendar.setTimeInMillis(0);
   calendar.set(Calendar.HOUR_OF_DAY, hours);
   calendar.set(Calendar.MINUTE, minutes);
 }
Beispiel #20
0
  public static CoveringInfo getWeeklyCoveringInfo(Date from, Date to) {
    int dayDiff = 0;
    Date tmpFrom = from;
    while (tmpFrom.before(to)) {
      tmpFrom = DateUtils.addDays(tmpFrom, 1);
      dayDiff++;
    }

    if (dayDiff < 7) {
      return new CoveringInfo(0, false);
    }

    Calendar cal = Calendar.getInstance();
    cal.setTime(from);
    int fromWeek = cal.get(Calendar.WEEK_OF_YEAR);
    int fromDay = cal.get(Calendar.DAY_OF_WEEK);
    int fromYear = cal.get(YEAR);

    cal.clear();
    cal.set(YEAR, fromYear);
    cal.set(Calendar.WEEK_OF_YEAR, fromWeek);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    int maxDayInWeek = cal.getActualMaximum(Calendar.DAY_OF_WEEK);
    Date fromWeekStartDate = cal.getTime();
    boolean coverable = dayDiff % 7 == 0;
    if (fromWeekStartDate.before(from)) {
      // Count from the start of next week
      dayDiff -= (maxDayInWeek - (fromDay - Calendar.SUNDAY));
      coverable = false;
    }

    return new CoveringInfo(dayDiff / 7, coverable);
  }
  /**
   * 获取智能生日
   *
   * @param birthday
   * @param needYear
   * @return
   */
  public static String getSmartBirthday(long birthday, boolean needYear) {
    int[] birthdayDetails = getDateDetail(birthday);
    int[] nowDetails = getDateDetail(System.currentTimeMillis());

    Calendar birthdayCalendar = Calendar.getInstance();
    birthdayCalendar.set(birthdayDetails[0], birthdayDetails[1], birthdayDetails[2]);

    Calendar nowCalendar = Calendar.getInstance();
    nowCalendar.set(nowDetails[0], nowDetails[1], nowDetails[2]);

    int days = birthdayCalendar.get(Calendar.DAY_OF_YEAR) - nowCalendar.get(Calendar.DAY_OF_YEAR);
    if (days < 8) {
      if (days >= 3) {
        return days + "天后";
      }
      if (days >= 2) {
        return TimeUtil.Day.NAME_THE_DAY_AFTER_TOMORROW;
      }
      if (days >= 1) {
        return TimeUtil.Day.NAME_TOMORROW;
      }
      if (days >= 0) {
        return TimeUtil.Day.NAME_TODAY;
      }
    }

    if (needYear) {
      return birthdayDetails[0] + "年" + birthdayDetails[1] + "月" + birthdayDetails[2] + "日";
    }
    return birthdayDetails[1] + "月" + birthdayDetails[2] + "日";
  }
  private void showDatepicker() {
    if (!locationListeners.isEmpty()) {
      return;
    }

    final DatePickerDialog datePickerDialog =
        new DatePickerDialog(
            this,
            new DatePickerDialog.OnDateSetListener() {
              @Override
              public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Calendar c = Calendar.getInstance();
                c.set(year, monthOfYear, dayOfMonth);

                if (DateTimes.isSameDay(mDate, c)) {
                  return;
                }

                mDate.set(year, monthOfYear, dayOfMonth);

                final TextView txtDate = (TextView) findViewById(R.id.txtDate);
                txtDate.setText(DateTimes.dateFormat().format(mDate));

                GPSHelper.loadTrackings(mDate);
                updateList();
              }
            },
            mDate.get(Calendar.YEAR),
            mDate.get(Calendar.MONTH),
            mDate.get(Calendar.DAY_OF_MONTH));

    datePickerDialog.show();
  }
  /**
   * Returns a speech formatted time, without a date, based on a period in the day. E.g. '12:35 in
   * the afternoon'
   *
   * @return
   */
  public static String getFormattedTime(Date date) {
    Calendar dateCal = Calendar.getInstance();
    dateCal.setTime(date);
    int hours = dateCal.get(Calendar.HOUR_OF_DAY);
    int minutes = dateCal.get(Calendar.MINUTE);
    String minuteString;

    String periodOfDay;
    if (hours < MORNING_THRESHOLD) {
      periodOfDay = " in the morning";
    } else if (hours < AFTERNOON_THRESHOLD) {
      periodOfDay = " in the afternoon";
    } else if (hours < EVENING_THRESHOLD) {
      periodOfDay = " in the evening";
    } else {
      periodOfDay = " at night";
    }

    hours = dateCal.get(Calendar.HOUR);
    hours = hours == 0 ? MIDNIGHT_HOUR : hours; // handle noon and midnight
    minuteString =
        minutes < MINUTE_TWO_DIGIT_THRESHOLD
            ? "0" + Integer.toString(minutes)
            : Integer.toString(minutes);
    String formattedTime = Integer.toString(hours) + ":" + minuteString + periodOfDay;
    return formattedTime;
  }
  @Override
  @NonNull
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    Calendar calendar = Calendar.getInstance();

    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);

    View v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_date, null);

    mDatePicker = (DatePicker) v.findViewById(R.id.dialog_date_picker);
    mDatePicker.init(year, month, day, null);

    return new AlertDialog.Builder(getActivity())
        .setView(v)
        .setTitle(R.string.date_picker_title)
        .setPositiveButton(
            android.R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                int year = mDatePicker.getYear();
                int month = mDatePicker.getMonth();
                int day = mDatePicker.getDayOfMonth();
                Date date = new GregorianCalendar(year, month, day).getTime();

                sendResult(Activity.RESULT_OK, date);
              }
            })
        .create();
  }
 /** 显示选择宝贝生日的弹窗 */
 private void showBirthdayDialog() {
   if (mBirthdayDialog == null) {
     mBirthdayDialog = new BaseDialog(this);
     mBirthdayDialog.setWindow(R.style.alpha_animation, 0.3f);
     mBirthdayDialog.setContentView(R.layout.dialog_select_birthday);
     mDatePicker = (DatePicker) mBirthdayDialog.findViewById(R.id.date_picker);
     Calendar cal = Calendar.getInstance();
     cal.setTimeInMillis(System.currentTimeMillis());
     mDatePicker.init(
         cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), null);
     mBirthdayDialog
         .findViewById(R.id.btn_ok)
         .setOnClickListener(
             new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                 if (mDatePicker != null) {
                   String birthday =
                       String.format(
                           "%d年%02d月%02d日",
                           mDatePicker.getYear(),
                           mDatePicker.getMonth() + 1,
                           mDatePicker.getDayOfMonth());
                   mTvBabyBirthday.setText(birthday);
                 }
                 if (mBirthdayDialog != null) {
                   mBirthdayDialog.dismiss();
                 }
               }
             });
   }
   mBirthdayDialog.show();
 }
  /**
   * 生成查询参数Map
   *
   * @return Map<String, Object>
   */
  private Map<String, Object> genParamMap(String condition) {
    Map<String, Object> params = new HashMap<String, Object>();

    if ("default".equals(flag)) {
      Calendar cal = Calendar.getInstance();
      cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1);
      String eDate = dateFormat.format(cal.getTime());
      cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 6);
      String sDate = dateFormat.format(cal.getTime());
      params.put("beginDate", sDate);
      params.put("endDate", eDate);

      // 设置日期过滤框默认值
      statParams.put("beginDate", sDate);
      statParams.put("endDate", eDate);
    }

    if (StringUtils.isNotBlank(statParams.get("processType"))) {
      params.put("processType", statParams.get("processType"));
    }

    if (StringUtils.isNotBlank(statParams.get("beginDate"))) {
      params.put("beginDate", statParams.get("beginDate"));
    }

    if (StringUtils.isNotBlank(statParams.get("endDate"))) {
      params.put("endDate", statParams.get("endDate"));
    }

    return params;
  }
Beispiel #27
0
  public static String getDateAsDDMMYYYYWithTimestamp(Date inputDate) {
    if (GenericUtils.isNotNull(inputDate)) {
      Calendar cal = Calendar.getInstance();
      cal.setTime(inputDate);
      String day = new Integer(cal.get(Calendar.DATE)).toString();
      String mm = new Integer(cal.get(Calendar.MONTH) + 1).toString();
      String year = new Integer(cal.get(Calendar.YEAR)).toString();
      String hours = new Integer(cal.get(Calendar.HOUR_OF_DAY)).toString();
      String minutes = new Integer(cal.get(Calendar.MINUTE)).toString();
      String seconds = new Integer(cal.get(Calendar.SECOND)).toString();

      return StringUtils.leftPad(day, 2, "0")
          + DateUtils.DATE_SEPARATOR_CHAR
          + StringUtils.leftPad(mm, 2, "0")
          + DateUtils.DATE_SEPARATOR_CHAR
          + year
          + PortalConstant.SINGLE_SPACE
          + StringUtils.leftPad(hours, 2, "0")
          + PortalConstant.COLON
          + StringUtils.leftPad(minutes, 2, "0")
          + PortalConstant.COLON
          + StringUtils.leftPad(seconds, 2, "0");
    }

    return PortalConstant.BLANK_STRING;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_novo_gasto);

    Calendar calendar = Calendar.getInstance();
    ano = calendar.get(Calendar.YEAR);
    mes = calendar.get(Calendar.MONTH);
    dia = calendar.get(Calendar.DAY_OF_MONTH);

    dataGasto = (Button) findViewById(R.id.data);
    dataGasto.setText(dia + "/" + (mes + 1) + "/" + ano);

    ArrayAdapter<CharSequence> adapter =
        ArrayAdapter.createFromResource(
            this, R.array.categoria_gasto, android.R.layout.simple_spinner_item);

    categoria = (Spinner) findViewById(R.id.categoria);
    categoria.setAdapter(adapter);

    String viagemDestino = getIntent().getExtras().getString(Constantes.VIAGEM_DESTINO);

    destino = (TextView) findViewById(R.id.destino);
    destino.setText(viagemDestino);

    valor = (EditText) findViewById(R.id.valor);
    descricao = (EditText) findViewById(R.id.descricao);
    local = (EditText) findViewById(R.id.local);

    helper = new DataBaseHelper(this);
  }
Beispiel #29
0
  public ArrayList<SmallPrayer> getTodayServices() {
    ArrayList<String> services = new ArrayList<String>();

    AppUser appUserInstance = AppUser.getInstance();
    ArrayList<DailyEvents> dailyEvents = appUserInstance.getCurrentCommunity().getDailyEvents();

    Calendar calendar = Calendar.getInstance();
    String day = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
    String month = String.valueOf(calendar.get(Calendar.MONTH) + 1);
    String year = String.valueOf(calendar.get(Calendar.YEAR));

    if (Integer.valueOf(day) < 10) day = "0" + day;

    if (Integer.valueOf(month) < 10) month = "0" + month;

    String todayDateString =
        String.valueOf(
            String.valueOf(day) + "/" + String.valueOf(month) + "/" + String.valueOf(year));

    for (int i = 0; i < dailyEvents.size(); i++) {
      DailyEvents singleDay = dailyEvents.get(i);
      if (todayDateString.equals(singleDay.getDate())) {
        if (singleDay.getPrayers().size() > 0) {
          return singleDay.getPrayers().get(0).getSmallPrayers();
        }
      }
    }

    return null;
  }
Beispiel #30
0
  /**
   * 获取两个日期之间的间隔日期
   *
   * @author modi
   * @version 1.0.0
   */
  public static int getDaysBetween(final String beginDate, final String endDate) {

    try {
      final SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.SIMPLIFIED_CHINESE);
      final Date bDate = format.parse(beginDate);
      final Date eDate = format.parse(endDate);
      Calendar d1 = new GregorianCalendar();
      d1.setTime(bDate);
      final Calendar d2 = new GregorianCalendar();
      d2.setTime(eDate);

      if (d1.after(d2)) {
        return 0;
      }

      int days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR);
      final int y2 = d2.get(Calendar.YEAR);
      if (d1.get(Calendar.YEAR) != y2) {
        d1 = (Calendar) d1.clone();
        do {
          days += d1.getActualMaximum(Calendar.DAY_OF_YEAR); // 得到当年的实际天数
          d1.add(Calendar.YEAR, 1);
        } while (d1.get(Calendar.YEAR) != y2);
      }
      return days;
    } catch (ParseException e) {
      return 0;
    }
  }