コード例 #1
0
ファイル: DateUtils.java プロジェクト: xiegang/commons
 /**
  * 判断两个两个时间是不是同一个星期
  *
  * @param cal1
  * @param cal2
  * @return
  */
 public static boolean isSameWeek(Calendar cal1, Calendar cal2) {
   cal1.setFirstDayOfWeek(Calendar.MONDAY);
   cal2.setFirstDayOfWeek(Calendar.MONDAY);
   return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA)
       && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
       && cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR));
 }
コード例 #2
0
 public void createCalendar() {
   List<Service> services = db.getCalendars();
   Calendar start = null;
   Calendar end = null;
   int doyStart, doyEnd, dow = -1;
   int[] validityVector = null;
   boolean[] validity = null;
   String dbVector = null;
   for (Service s : services) {
     start = new GregorianCalendar();
     end = new GregorianCalendar();
     start.setFirstDayOfWeek(Calendar.MONDAY);
     end.setFirstDayOfWeek(Calendar.MONDAY);
     validityVector = new int[366];
     dbVector = new String();
     for (int i = 0; i < 366; i++) validityVector[i] = 0;
     start.setTimeInMillis(parseDateToMillis(s.getStartDate()));
     end.setTimeInMillis(parseDateToMillis(s.getEndDate()));
     doyStart = start.get(Calendar.DAY_OF_YEAR);
     doyEnd = end.get(Calendar.DAY_OF_YEAR);
     validity = s.getValidity();
     Calendar c = (Calendar) start.clone();
     while (doyStart <= doyEnd) {
       dow = c.get(Calendar.DAY_OF_WEEK);
       if (validity[dow - 1]) validityVector[doyStart - 1] = 1;
       c.add(Calendar.DAY_OF_YEAR, +1);
       doyStart = c.get(Calendar.DAY_OF_YEAR);
     }
     for (int i = 0; i < 366; i++) dbVector += validityVector[i];
     db.insertService(s.getId(), s.getStartDate(), s.getEndDate(), dbVector, city);
   }
 }
  // Get all item in a date (Today, Tomorrow, Yesterday)
  public Cursor getAll_inDate(String date, String col) {
    Cursor cur = null;
    String sql;
    String orderBy = "";
    if (!col.equals("")) orderBy = " order by " + col;
    today = Calendar.getInstance();
    tomorrow = Calendar.getInstance();
    yesterday = Calendar.getInstance();

    today.setFirstDayOfWeek(Calendar.MONDAY);
    tomorrow.setFirstDayOfWeek(Calendar.MONDAY);
    yesterday.setFirstDayOfWeek(Calendar.MONDAY);

    if (date.equals("Today")) {
      date = format.format(today.getTime());
      Log.v("DataHelper", date);
      sql = "select * from " + TABLE_NAME + " where " + DUE + "=\"" + date + "\"" + orderBy;
      cur = shoppingDB.rawQuery(sql, null);
      return cur;
    } else if (date.equals("Tomorrow")) {
      tomorrow.add(Calendar.DAY_OF_MONTH, 1);
      date = format.format(tomorrow.getTime());
      sql = "select * from " + TABLE_NAME + " where " + DUE + "=\"" + date + "\"" + orderBy;
      cur = shoppingDB.rawQuery(sql, null);
      return cur;
    } else if (date.equals("Yesterday")) {
      yesterday.add(Calendar.DAY_OF_MONTH, -1);
      date = format.format(yesterday.getTime());
      sql = "select * from " + TABLE_NAME + " where " + DUE + "=\"" + date + "\"" + orderBy;
      cur = shoppingDB.rawQuery(sql, null);
      return cur;
    }
    return null;
  }
コード例 #4
0
ファイル: NotesList.java プロジェクト: jeongjaehong/webbibles
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    dao = new NoteDao(this, null, Prefs.getSDCardUse(this));

    setContentView(R.layout.notelist_view);

    setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);

    mBibleID = getIntent().getLongExtra("bibleid", new Long(-1));
    mVersion = getIntent().getIntExtra("version", -1);
    mBook = getIntent().getIntExtra("book", -1);
    mChapter = getIntent().getIntExtra("chapter", -1);
    mVerse = getIntent().getIntExtra("verse", -1);

    // 검색조건
    if ("Y".equals(getIntent().getStringExtra("SEARCH"))) {
      searchYN = getIntent().getStringExtra("SEARCH");
      searchVersion = getIntent().getIntExtra("version", 0);
      searchTestment = getIntent().getIntExtra("testment", 0);
      searchOperator = getIntent().getIntExtra("operator", 0);
      searchKeyword1 = getIntent().getStringExtra("keyword1");
      searchKeyword2 = getIntent().getStringExtra("keyword2");
    }

    toCalendar = Calendar.getInstance();
    toCalendar.setFirstDayOfWeek(Calendar.SUNDAY);
    fromCalendar = Calendar.getInstance();
    fromCalendar.setFirstDayOfWeek(Calendar.SUNDAY);
    fromCalendar.add(Calendar.MONTH, -1);
    ((EditText) findViewById(R.id.from_date)).setText(Common.fmtDate(fromCalendar));
    ((EditText) findViewById(R.id.to_date)).setText(Common.fmtDate(toCalendar));

    mListView = (ListView) findViewById(R.id.ContentsListView);
    mListView.setOnCreateContextMenuListener(this);
    // mListView.setOnTouchListener(this);
    mListView.setOnItemClickListener(new listOnItemClickListener());

    Spinner chapter_spinner = (Spinner) findViewById(R.id.chapters);
    chapter_spinner.setOnItemSelectedListener(new ChapterOnItemSelectedListener());
    // chapter_spinner.setOnCreateContextMenuListener(this);

    Spinner spin_books = (Spinner) findViewById(R.id.books);
    ArrayAdapter<CharSequence> adapter_books =
        ArrayAdapter.createFromResource(
            this, R.array.all_testment, android.R.layout.simple_spinner_item);
    adapter_books.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin_books.setAdapter(adapter_books);

    spin_books.setOnItemSelectedListener(new BookOnItemSelectedListener());
    spin_books.setSelection(mBook);

    findViewById(R.id.btn_prev).setOnClickListener(this);
    findViewById(R.id.btn_next).setOnClickListener(this);
    findViewById(R.id.from_date).setOnClickListener(this);
    findViewById(R.id.to_date).setOnClickListener(this);
  }
コード例 #5
0
ファイル: DateUtils.java プロジェクト: vicklin/stock-AI
 /**
  * 取得指定日期的同一周内日期
  *
  * @param Date      日期字符串 格式: yyyy-MM-dd HH:mm:ss 或 yyyy-MM-dd
  * @param dateValue 要显示的日期(周一到周日)
  * @param flag      标志,1-向前查找日期 2-向后查找日期
  * @return 指定周几的日期字符串
  * <code>
  * getWeekDay("2009-5-25", Calendar.MONDAY,1) 返回: 2009-05-25 .
  * getWeekDay("2009-5-25", Calendar.SUNDAY,2) 返回: 2009-05-31 .
  * <code>
  * @throws ParseException
  * @author: ctf 陈廷峰
  * @since: 2009-5-25
  */
 public static String getWeekDay(String Date, int dateValue, int flag) throws ParseException {
   Calendar calObj = Calendar.getInstance();
   SimpleDateFormat sfObj = new SimpleDateFormat("yyyy-MM-dd");
   calObj.setTime(sfObj.parse(Date));
   if (dateValue != Calendar.SATURDAY) {
     if (flag == 1) { // 周一
       calObj.setFirstDayOfWeek(dateValue);
     } else { // 周日
       calObj.setFirstDayOfWeek(dateValue + 1);
     }
   }
   calObj.set(Calendar.DAY_OF_WEEK, dateValue);
   return sfObj.format(calObj.getTime());
 }
 public ShoppingDatabase(Context context) {
   today = Calendar.getInstance();
   tomorrow = Calendar.getInstance();
   yesterday = Calendar.getInstance();
   thisweek = Calendar.getInstance();
   thisweek.setFirstDayOfWeek(Calendar.MONDAY);
   nextweek = Calendar.getInstance();
   nextweek.setFirstDayOfWeek(Calendar.MONDAY);
   lastweek = Calendar.getInstance();
   lastweek.setFirstDayOfWeek(Calendar.MONDAY);
   later = Calendar.getInstance();
   format = new SimpleDateFormat("yyyy-MM-dd");
   formatReverse = new SimpleDateFormat("dd-MM-yyyy");
   this.mContext = context;
 }
コード例 #7
0
  public void cargarMesAnterior(int mes, int ano) {
    Calendar calendarioo = GregorianCalendar.getInstance();
    calendarioo.setFirstDayOfWeek(Calendar.MONDAY);
    calendarioo.set(
        ano,
        mes,
        calendarioo.getActualMinimum(Calendar.DAY_OF_MONTH),
        calendarioo.get(Calendar.HOUR_OF_DAY),
        calendarioo.get(Calendar.MINUTE),
        calendarioo.get(Calendar.SECOND));
    int primerDia = calendarioo.get(Calendar.DAY_OF_WEEK) - 2;

    Log.e("primerDia", primerDia + "");
    calendarioo.set(
        calendarioo.get(Calendar.YEAR),
        calendarioo.get(Calendar.MONTH) - 1,
        calendarioo.getActualMinimum(Calendar.DAY_OF_MONTH),
        calendarioo.get(Calendar.HOUR_OF_DAY),
        calendarioo.get(Calendar.MINUTE),
        calendarioo.get(Calendar.SECOND));
    if (primerDia == -1) {
      primerDia = 6;
    }

    int ultimoDia = calendarioo.getActualMaximum(Calendar.DAY_OF_MONTH);
    int diaPartida = ultimoDia - primerDia + 1;
    Log.e("primerDia", calendarioo.getFirstDayOfWeek() + "");

    for (int i = 0; i < primerDia; i++) {
      diasCalendarios.add(new DiasCalendario(diaPartida, diaPartida, mes, ano, 4));
      diaPartida++;
    }
  }
コード例 #8
0
  public void mesSiguiente(Calendar calendario, int mesSiguiente) {
    diasCalendarios.clear();
    diasCalendarios = new ArrayList<DiasCalendario>();
    Calendar calendarioSiguiente = GregorianCalendar.getInstance();
    calendarioSiguiente.set(
        calendario.get(Calendar.YEAR),
        calendario.get(Calendar.MONTH) + mesSiguiente,
        calendario.get(Calendar.DAY_OF_MONTH),
        calendario.get(Calendar.HOUR_OF_DAY),
        calendario.get(Calendar.MINUTE),
        calendario.get(Calendar.SECOND));

    cargarMesAnterior(
        calendarioSiguiente.get(Calendar.MONTH), calendarioSiguiente.get(Calendar.YEAR));
    calendario.setFirstDayOfWeek(1);

    int dias = calendarioSiguiente.getActualMaximum(Calendar.DAY_OF_MONTH);
    int mes = calendario.get(Calendar.MONTH) + 1;
    int year = calendario.get(Calendar.YEAR);

    int newMes = mes + mesSiguiente;
    setNombreMes(newMes);
    Log.e("MES SIGUIENTE", "mes" + newMes);
    Log.e("MESSS", ":" + mesSiguiente);

    DiasCalendario diaGrilla;
    for (int i = 0; i != dias; i++) {
      diaGrilla = new DiasCalendario(i + 1, i + 1, mes, year, (int) (Math.random() * 3) + 1);
      diasCalendarios.add(diaGrilla);
    }

    btnMesAnterior.setEnabled(true);
    GrillaAdapter grillaAdaptador = new GrillaAdapter(diasCalendarios, this);
    grilla.setAdapter(grillaAdaptador);
  }
コード例 #9
0
  @Override
  protected void executeJob(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
    if (dayOfWeek != Calendar.MONDAY && dayOfWeek != Calendar.THURSDAY) {
      return;
    }

    if (lock) {
      return;
    } else {
      lock = true;
      try {
        LOG.info("后台上周每个汽配店铺所关心的配件 汽修版的上周销量、入库量统计");
        LOG.info("开始时间:" + DateUtil.dateLongToStr(System.currentTimeMillis()));
        IPreciseRecommendService service =
            ServiceManager.getService(IPreciseRecommendService.class);
        service.salesInventoryMonthStat();

      } catch (Exception e) {
        LOG.error("/SalesInventoryWeekStatSchedule method=executeJob 上周销量、入库量统计失败");
        LOG.error(e.getMessage(), e);
      } finally {
        LOG.info("后台结束上周销量、入库量统计");
        lock = false;
        LOG.info("结束时间:" + DateUtil.dateLongToStr(System.currentTimeMillis()));
      }
    }
  }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "setFirstDayOfWeek",
      args = {int.class})
  public void test_setFirstDayOfWeekI() {
    Calendar cal = Calendar.getInstance();

    for (int i = 0; i < 10; i++) {
      cal.setFirstDayOfWeek(i);
      assertEquals(i, cal.getFirstDayOfWeek());
    }
    cal.setLenient(false);
    cal.setFirstDayOfWeek(10);
    cal.setFirstDayOfWeek(-10);
  }
コード例 #11
0
 /**
  * Returns the week of the year according to the ISO 8601 specification. The spec defines the
  * first week of the year as the week which contains at least 4 days of the new year. The week
  * starts at Monday. Therefore December 29th - 31th could belong to the next year and January 1st
  * - 3th could belong to the previous year. If January 1st is on Thursday (or earlier) it belongs
  * to the first week, otherwise to the last week of the previous year. Hence January 4th always
  * belongs to the first week while the December 28th always belongs to the last week.
  *
  * @author Robert Rathsack
  * @param date the date object which week of year should be calculated
  * @return the week of the year
  */
 public static int getIsoWeek(java.util.Date date) {
   Calendar c = Calendar.getInstance();
   c.setTimeInMillis(date.getTime());
   c.setFirstDayOfWeek(Calendar.MONDAY);
   c.setMinimalDaysInFirstWeek(4);
   return c.get(Calendar.WEEK_OF_YEAR);
 }
コード例 #12
0
 /**
  * 返回某天所在周的周几的日期
  *
  * @param date
  * @param day 周几,1、2、3、4、5、6、7
  * @return
  */
 public static Date getDayOfWeek(Date date, int day) {
   Calendar c = new GregorianCalendar();
   c.setFirstDayOfWeek(Calendar.MONDAY);
   c.setTime(date);
   c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + day - 1);
   return c.getTime();
 }
コード例 #13
0
 /**
  * get calendar by user setting (timezone, first day of week)
  *
  * @param calendarSetting
  * @return calendar object
  */
 public static Calendar getCalendarInstanceBySetting(CalendarSetting calendarSetting) {
   Calendar calendar = GregorianCalendar.getInstance();
   calendar.setLenient(false);
   calendar.setTimeZone(TimeZone.getTimeZone(calendarSetting.getTimeZone()));
   calendar.setFirstDayOfWeek(Integer.parseInt(calendarSetting.getWeekStartOn()));
   calendar.setMinimalDaysInFirstWeek(4);
   return calendar;
 }
コード例 #14
0
 /** 获取本周结束的时间 */
 public static Date getCurrentWeekEndDate() {
   Calendar currentDate = Calendar.getInstance();
   currentDate.setFirstDayOfWeek(Calendar.MONDAY);
   currentDate.set(Calendar.HOUR_OF_DAY, 23);
   currentDate.set(Calendar.MINUTE, 59);
   currentDate.set(Calendar.SECOND, 59);
   currentDate.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
   return currentDate.getTime();
 }
コード例 #15
0
ファイル: UIWeekView.java プロジェクト: nttuyen/calendar
 public java.util.Calendar getEndDateOfWeek() throws Exception {
   java.util.Calendar temCal = getInstanceTempCalendar();
   if (isShowCustomView_) temCal.setFirstDayOfWeek(Calendar.SUNDAY);
   temCal.setTime(getBeginDateOfWeek().getTime());
   int amout = 6;
   if (isShowCustomView_) amout = amout - 2;
   temCal.add(Calendar.DATE, amout);
   return getEndDay(temCal);
 }
コード例 #16
0
ファイル: DateTimeUtils.java プロジェクト: yufeng1982/EMP
 public static java.util.Calendar getStartDateThisWeek(int firstDayOfWeek) {
   java.util.Calendar cal = java.util.Calendar.getInstance();
   cal.setFirstDayOfWeek(firstDayOfWeek);
   cal.set(java.util.Calendar.DAY_OF_WEEK, firstDayOfWeek);
   cal.set(java.util.Calendar.HOUR_OF_DAY, 0);
   cal.set(java.util.Calendar.MINUTE, 0);
   cal.set(java.util.Calendar.SECOND, 0);
   cal.set(java.util.Calendar.MILLISECOND, 0);
   return cal;
 }
コード例 #17
0
ファイル: DateTimeUtils.java プロジェクト: yufeng1982/EMP
 public static java.util.Calendar getMinDateThisWeek() {
   java.util.Calendar cal = java.util.Calendar.getInstance();
   cal.setFirstDayOfWeek(java.util.Calendar.SUNDAY);
   cal.set(java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.SUNDAY);
   cal.set(java.util.Calendar.HOUR_OF_DAY, 0);
   cal.set(java.util.Calendar.MINUTE, 0);
   cal.set(java.util.Calendar.SECOND, 0);
   cal.set(java.util.Calendar.MILLISECOND, 0);
   return cal;
 }
コード例 #18
0
ファイル: TimeUtil.java プロジェクト: DSstar/Loliclub
 /**
  * 获取一星期的最后一毫秒
  *
  * @param timeInMillis
  * @return
  */
 public static long getLastSecondInWeek(long timeInMillis) {
   Calendar calendar = Calendar.getInstance();
   calendar.setTimeInMillis(timeInMillis);
   calendar.setFirstDayOfWeek(Calendar.SUNDAY);
   calendar.set(Calendar.DAY_OF_WEEK, calendar.getActualMaximum(Calendar.DAY_OF_WEEK));
   calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
   calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
   calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
   calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND));
   return calendar.getTimeInMillis();
 }
コード例 #19
0
  /**
   * 获取上周最后一天的日期 最后一天为星期天
   *
   * @return
   */
  public static Date getPreWeekLastDay() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());

    calendar.setFirstDayOfWeek(1);
    int week = calendar.get(Calendar.DAY_OF_WEEK);
    int day = calendar.get(Calendar.DAY_OF_MONTH);

    calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), day + 1 - week);
    return calendar.getTime();
  }
コード例 #20
0
ファイル: TimeUtils.java プロジェクト: caocf/bi-platform
 /**
  * 得到指定时间所在周周日
  *
  * @param day
  * @return
  */
 protected static Date getSundayOfThisWeek(Date day) {
   Calendar calendar = Calendar.getInstance();
   calendar.setFirstDayOfWeek(Calendar.MONDAY);
   calendar.setTime(day);
   int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
   if (dayOfWeek == 0) {
     dayOfWeek = 7;
   }
   calendar.add(Calendar.DATE, -dayOfWeek + 7);
   return calendar.getTime();
 }
コード例 #21
0
ファイル: DateTimeUtils.java プロジェクト: yufeng1982/EMP
 public static java.util.Calendar getMaxDateLastWeek() {
   java.util.Calendar cal = java.util.Calendar.getInstance();
   cal.setFirstDayOfWeek(java.util.Calendar.SUNDAY);
   cal.add(java.util.Calendar.DATE, -7);
   cal.set(java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.SATURDAY);
   cal.set(java.util.Calendar.HOUR_OF_DAY, 0);
   cal.set(java.util.Calendar.MINUTE, 0);
   cal.set(java.util.Calendar.SECOND, 0);
   cal.set(java.util.Calendar.MILLISECOND, 0);
   return cal;
 }
コード例 #22
0
 public Calendar read(Kryo kryo, Input input, Class<Calendar> type) {
   Calendar result = Calendar.getInstance(timeZoneSerializer.read(kryo, input, TimeZone.class));
   result.setTimeInMillis(input.readLong(true));
   result.setLenient(input.readBoolean());
   result.setFirstDayOfWeek(input.readInt(true));
   result.setMinimalDaysInFirstWeek(input.readInt(true));
   long gregorianChange = input.readLong(false);
   if (gregorianChange != DEFAULT_GREGORIAN_CUTOVER)
     if (result instanceof GregorianCalendar)
       ((GregorianCalendar) result).setGregorianChange(new Date(gregorianChange));
   return result;
 }
コード例 #23
0
ファイル: CronTabTest.java プロジェクト: nlalevee/jenkins
 @Bug(8401)
 public void testFloor4() throws Exception {
   // conflict between DoM and DoW. In this we need to find a day that's the first day of a month
   // and Sunday in 2010
   CronTab x = new CronTab("0 0 1 * 0");
   Calendar c = new GregorianCalendar(2011, 0, 1, 15, 55);
   c.setFirstDayOfWeek(MONDAY);
   // the last such day in 2010 is Aug 1st
   GregorianCalendar answer = new GregorianCalendar(2010, 7, 1, 0, 0);
   answer.setFirstDayOfWeek(MONDAY);
   compare(answer, x.floor(c));
 }
コード例 #24
0
ファイル: TimeUtils.java プロジェクト: caocf/bi-platform
 /**
  * 获取指定时间对于所在年来说应该在第几周
  *
  * @param day yyyyMMdd格式时间字符串
  * @return
  */
 public static int getWeekIndex(String day) throws Exception {
   Date current = getCurrentDay();
   if (!StringUtils.isEmpty(day)) {
     SimpleDateFormat sdf = new SimpleDateFormat();
     sdf.applyPattern(TimeRangeDetail.FORMAT_STRING);
     current = sdf.parse(day);
   }
   Calendar cal = Calendar.getInstance();
   cal.setFirstDayOfWeek(Calendar.MONDAY);
   cal.setTime(current);
   return cal.get(Calendar.WEEK_OF_YEAR);
 }
コード例 #25
0
ファイル: UIWeekView.java プロジェクト: nttuyen/calendar
 public java.util.Calendar getBeginDateOfWeek() throws Exception {
   java.util.Calendar temCal = getInstanceTempCalendar();
   temCal.setTime(calendar_.getTime());
   if (isShowCustomView_) temCal.setFirstDayOfWeek(Calendar.SUNDAY);
   if (temCal.getFirstDayOfWeek() > temCal.get(Calendar.DAY_OF_WEEK)) {
     temCal.add(java.util.Calendar.WEEK_OF_YEAR, -1);
   }
   int amout = temCal.getFirstDayOfWeek() - temCal.get(Calendar.DAY_OF_WEEK);
   if (isShowCustomView_) amout = amout + 1;
   temCal.add(Calendar.DATE, amout);
   return getBeginDay(temCal);
 }
コード例 #26
0
 private Calendar resetAndGetWorkingCalendar() {
   month.copyTo(tempWorkingCalendar);
   tempWorkingCalendar.setFirstDayOfWeek(firstDayOfWeek);
   int dow = CalendarUtils.getDayOfWeek(tempWorkingCalendar);
   int delta = firstDayOfWeek - dow;
   // If the delta is positive, we want to remove a week
   boolean removeRow = showOtherMonths(showOtherDates) ? delta >= 0 : delta > 0;
   if (removeRow) {
     delta -= DEFAULT_DAYS_IN_WEEK;
   }
   tempWorkingCalendar.add(DATE, delta);
   return tempWorkingCalendar;
 }
コード例 #27
0
ファイル: DateUtil.java プロジェクト: koalhou/J2EE
  /** 获取当前周最后一天 小时分钟为23:59:59 */
  public static String getCurrentWeekLast() {
    StringBuffer str = new StringBuffer();
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
    Calendar c = new GregorianCalendar();
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setTime(new Date());
    // c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // Monday
    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); // Sunday
    str.append(df.format(c.getTime()));
    str.append(" 23:59:59");

    return str.toString();
  }
コード例 #28
0
ファイル: TimeUtil.java プロジェクト: DSstar/Loliclub
 /**
  * 获取一星期的第一毫秒
  *
  * @param timeInMillis
  * @param dayOfWeek 周的第一天。若为负数,则不设置,参照Calendar
  * @return
  */
 public static long getFirstSecondInWeek(long timeInMillis, int dayOfWeek) {
   if (dayOfWeek < 1 || dayOfWeek > 7) {
     Calendar calendar = Calendar.getInstance();
     calendar.setFirstDayOfWeek(dayOfWeek);
     calendar.setTimeInMillis(timeInMillis);
     calendar.set(Calendar.DAY_OF_WEEK, calendar.getActualMinimum(Calendar.DAY_OF_WEEK));
     calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
     calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
     calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
     calendar.set(Calendar.MILLISECOND, calendar.getActualMinimum(Calendar.MILLISECOND));
     return calendar.getTimeInMillis();
   } else return getFirstSecondInWeek(timeInMillis);
 }
コード例 #29
0
 /**
  * Returns the year according to the ISO week definition.
  *
  * @author Robert Rathsack
  * @param date the date object which year should be calculated
  * @return the year
  */
 public static int getIsoYear(java.util.Date date) {
   Calendar cal = Calendar.getInstance();
   cal.setTimeInMillis(date.getTime());
   cal.setFirstDayOfWeek(Calendar.MONDAY);
   cal.setMinimalDaysInFirstWeek(4);
   int year = getYear(cal);
   int month = cal.get(Calendar.MONTH);
   int week = cal.get(Calendar.WEEK_OF_YEAR);
   if (month == 0 && week > 51) {
     year--;
   } else if (month == 11 && week == 1) {
     year++;
   }
   return year;
 }
コード例 #30
0
ファイル: DateUtils.java プロジェクト: jesubiag/yotelopaso
 public static Date getEndDate(String type) {
   Calendar c = Calendar.getInstance();
   c.setFirstDayOfWeek(Calendar.MONDAY);
   switch (type) {
     case MONTHLY:
       c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
       break;
     case WEEKLY:
       c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
       break;
     case DAILY:
       c.set(Calendar.HOUR_OF_DAY, c.getActualMaximum(Calendar.HOUR_OF_DAY));
       break;
   }
   return c.getTime();
 }