當前位置: 首頁>>代碼示例>>Java>>正文


Java DateTime.plusHours方法代碼示例

本文整理匯總了Java中org.joda.time.DateTime.plusHours方法的典型用法代碼示例。如果您正苦於以下問題:Java DateTime.plusHours方法的具體用法?Java DateTime.plusHours怎麽用?Java DateTime.plusHours使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joda.time.DateTime的用法示例。


在下文中一共展示了DateTime.plusHours方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isInvasionTime

import org.joda.time.DateTime; //導入方法依賴的package包/類
public boolean isInvasionTime(DateTime startDate, DateTime current) {
    //For the record, the invasion times themselves are NOT random. They are 6 hours on, 12.5 hours off, repeating forever.
    //This gives an invasion happening at every possible hour of the day over a 3 day period.
    DateTime start = new DateTime(startDate);
    boolean loop = true;
    boolean enabled = true;
    while (loop) {
        if (enabled) {
            start = start.plusHours(6);
            if (current.isBefore(start)) {
                loop = false;
            } else {
                enabled = false;
            }
        } else {
            start = start.plusHours(12).plusMinutes(30);
            if (current.isBefore(start)) {
                loop = false;
            } else {
                enabled = true;
            }
        }

    }
    return enabled;
}
 
開發者ID:greatman,項目名稱:legendarybot,代碼行數:27,代碼來源:InvasionCommand.java

示例2: getIncrementUrl

import org.joda.time.DateTime; //導入方法依賴的package包/類
@Override
public String getIncrementUrl(Market market) {
    if (market == null) {
        return null;
    }
    // http://img.yingyonghui.com/interface/ijinshan/ijinshan_on_{day}_{hour}.csv.gz
    DateTime dt = new DateTime(market.getIncrementLastTime());
    dt = dt.plusHours(1);
    String date = new java.text.SimpleDateFormat("yyyyMMdd_H").format(dt.toDate());
    String incrementApiUrl = market.getIncrementUrl();
    StringBuilder url = new StringBuilder(incrementApiUrl.length());
    url.append(incrementApiUrl);
    if (!incrementApiUrl.endsWith("/")) {
        url.append("/");
    }
    url.append("ijinshan_on_");
    url.append(date);
    url.append(".csv.gz");
    url.append("?t=");
    url.append(System.currentTimeMillis());
    final String fileUrl = url.toString();
    logger.info("AppChina : {}", fileUrl);
    return fileUrl;
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:25,代碼來源:AccessAppChinaDaoImpl.java

示例3: getIncrementUrl

import org.joda.time.DateTime; //導入方法依賴的package包/類
@Override
public String getIncrementUrl(Market market) {
    if (market == null) {
        return null;
    }
    // http://www.yingyong.so/shoujikong/ijinshan_shoujikong_on_{day}_{hour}.csv.gz
    DateTime dt = new DateTime(market.getIncrementLastTime());
    dt = dt.plusHours(1);
    String date = new java.text.SimpleDateFormat("yyyyMMdd_H").format(dt.toDate());
    String incrementApiUrl = market.getIncrementUrl();
    StringBuilder url = new StringBuilder(incrementApiUrl.length());
    url.append(incrementApiUrl);
    if (!incrementApiUrl.endsWith("/")) {
        url.append("/");
    }
    url.append("ijinshan_shoujikong_on_");
    url.append(date);
    url.append(".csv.gz");
    url.append("?t=");
    url.append(System.currentTimeMillis());
    logger.debug("URL : {}", url.toString());
    return url.toString();
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:24,代碼來源:AccessShoujikong_ChannelDaoImpl.java

示例4: getIncrementUrl

import org.joda.time.DateTime; //導入方法依賴的package包/類
@Override
public String getIncrementUrl(Market market) {
    if (market == null) {
        return null;
    }
    // http://apk.91.com/data/ijinshan_on_{day}_{hour}.csv
    DateTime dt = new DateTime(market.getIncrementLastTime());
    dt = dt.plusHours(1);
    String date = new java.text.SimpleDateFormat("yyyyMMdd_H").format(dt.toDate());
    String incrementApiUrl = market.getIncrementUrl();
    StringBuilder url = new StringBuilder(incrementApiUrl.length());
    url.append(incrementApiUrl);
    if (!incrementApiUrl.endsWith("/")) {
        url.append("/");
    }
    url.append("ijinshan_on_");
    url.append(date);
    url.append(".csv.gz");
    url.append("?t=");
    url.append(System.currentTimeMillis());
    return url.toString();
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:23,代碼來源:AccessM91DaoImpl.java

示例5: getIncrementUrl

import org.joda.time.DateTime; //導入方法依賴的package包/類
@Override
public String getIncrementUrl(Market market) {
    if (market == null) {
        return null;
    }
    // http://www.yingyong.so/shoujikong/ijinshan_on_{day}_{hour}.csv.gz
    DateTime dt = new DateTime(market.getIncrementLastTime());
    dt = dt.plusHours(1);
    String date = new java.text.SimpleDateFormat("yyyyMMdd_H").format(dt.toDate());
    String incrementApiUrl = market.getIncrementUrl();
    StringBuilder url = new StringBuilder(incrementApiUrl.length());
    url.append(incrementApiUrl);
    if (!incrementApiUrl.endsWith("/")) {
        url.append("/");
    }
    url.append("ijinshan_on_");
    url.append(date);
    url.append(".csv.gz");
    url.append("?t=");
    url.append(System.currentTimeMillis());
    return url.toString();
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:23,代碼來源:AccessYingyongsoDaoImpl.java

示例6: createEvent_defaultCalendar

import org.joda.time.DateTime; //導入方法依賴的package包/類
@Test
public void createEvent_defaultCalendar() throws CalendarWriteException, IOException {
  //given
  final String summary = "<summary>";
  final DateTime from = DateTime.now();
  final DateTime to = from.plusHours(1);

  Map<String, CalendarCLIAdapter> calendar = new HashMap<>();
  calendar.put("default", mock(CalendarCLIAdapter.class));
  calendar.put("sec", mock(CalendarCLIAdapter.class));

  CalendarConfiguration.NAME_OF_DEFAULT_CALENDAR = "default";
  doReturn(calendar).when(toTest).getCalendars();
  doReturn("<uid-def>").when(calendar.get("default")).createEvent(any(), any(), any());
  doReturn("<uid-sec>").when(calendar.get("sec")).createEvent(any(), any(), any());

  //when
  final String result = toTest.createEvent(null, summary, from, to);

  //then
  assertEquals("<uid-def>", result);
  verify(calendar.get("default"), times(1)).createEvent(
      same(summary), same(from), same(to)
  );
  verify(calendar.get("sec"), never()).createEvent(any(), any(), any());
}
 
開發者ID:rainu,項目名稱:alexa-skill,代碼行數:27,代碼來源:CalendarServiceTest.java

示例7: createEvent_customCalendar

import org.joda.time.DateTime; //導入方法依賴的package包/類
@Test
public void createEvent_customCalendar() throws CalendarWriteException, IOException {
  //given
  final String summary = "<summary>";
  final DateTime from = DateTime.now();
  final DateTime to = from.plusHours(1);

  Map<String, CalendarCLIAdapter> calendar = new HashMap<>();
  calendar.put("default", mock(CalendarCLIAdapter.class));
  calendar.put("sec", mock(CalendarCLIAdapter.class));

  CalendarConfiguration.NAME_OF_DEFAULT_CALENDAR = "default";
  doReturn(calendar).when(toTest).getCalendars();
  doReturn("<uid-def>").when(calendar.get("default")).createEvent(any(), any(), any());
  doReturn("<uid-sec>").when(calendar.get("sec")).createEvent(any(), any(), any());

  //when
  final String result = toTest.createEvent("sec", summary, from, to);

  //then
  assertEquals("<uid-sec>", result);
  verify(calendar.get("sec"), times(1)).createEvent(
      same(summary), same(from), same(to)
  );
  verify(calendar.get("default"), never()).createEvent(any(), any(), any());
}
 
開發者ID:rainu,項目名稱:alexa-skill,代碼行數:27,代碼來源:CalendarServiceTest.java

示例8: createEvent_calendarThrowsException

import org.joda.time.DateTime; //導入方法依賴的package包/類
@Test(expected = CalendarWriteException.class)
public void createEvent_calendarThrowsException() throws CalendarWriteException, IOException {
  //given
  final String summary = "<summary>";
  final DateTime from = DateTime.now();
  final DateTime to = from.plusHours(1);

  Map<String, CalendarCLIAdapter> calendar = new HashMap<>();
  calendar.put("default", mock(CalendarCLIAdapter.class));

  CalendarConfiguration.NAME_OF_DEFAULT_CALENDAR = "default";
  doReturn(calendar).when(toTest).getCalendars();
  doThrow(new IOException()).when(calendar.get("default")).createEvent(any(), any(), any());

  //when
  toTest.createEvent(null, summary, from, to);
}
 
開發者ID:rainu,項目名稱:alexa-skill,代碼行數:18,代碼來源:CalendarServiceTest.java

示例9: prepareIndex

import org.joda.time.DateTime; //導入方法依賴的package包/類
private void prepareIndex(DateTime date, int numHours, int stepSizeHours, int idxIdStart) throws IOException, InterruptedException, ExecutionException {
    IndexRequestBuilder[] reqs = new IndexRequestBuilder[numHours];
    for (int i = idxIdStart; i < idxIdStart + reqs.length; i++) {
        reqs[i - idxIdStart] = client().prepareIndex("idx2", "type", "" + i).setSource(jsonBuilder().startObject().field("date", date).endObject());
        date = date.plusHours(stepSizeHours);
    }
    indexRandom(true, reqs);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:DateHistogramOffsetIT.java

示例10: testSingleValueWithTimeZone

import org.joda.time.DateTime; //導入方法依賴的package包/類
public void testSingleValueWithTimeZone() throws Exception {
    prepareCreate("idx2").addMapping("type", "date", "type=date").execute().actionGet();
    IndexRequestBuilder[] reqs = new IndexRequestBuilder[5];
    DateTime date = date("2014-03-11T00:00:00+00:00");
    for (int i = 0; i < reqs.length; i++) {
        reqs[i] = client().prepareIndex("idx2", "type", "" + i).setSource(jsonBuilder().startObject().field("date", date).endObject());
        date = date.plusHours(1);
    }
    indexRandom(true, reqs);

    SearchResponse response = client().prepareSearch("idx2")
            .setQuery(matchAllQuery())
            .addAggregation(dateHistogram("date_histo")
                    .field("date")
                    .timeZone(DateTimeZone.forID("-02:00"))
                    .dateHistogramInterval(DateHistogramInterval.DAY)
                    .format("yyyy-MM-dd:HH-mm-ssZZ"))
            .execute().actionGet();

    assertThat(response.getHits().getTotalHits(), equalTo(5L));

    Histogram histo = response.getAggregations().get("date_histo");
    List<? extends Histogram.Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(2));

    Histogram.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo("2014-03-10:00-00-00-02:00"));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo("2014-03-11:00-00-00-02:00"));
    assertThat(bucket.getDocCount(), equalTo(3L));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:36,代碼來源:DateHistogramIT.java

示例11: testTimePlus

import org.joda.time.DateTime; //導入方法依賴的package包/類
/**
 * 時間加減操作,plus 負數時是向前推移
 */
@Test
public void testTimePlus() {
    // 獲取當前時間
    DateTime dt = new DateTime();
    String currentTime = dt.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("currentTime: " + currentTime);

    // 相對當前時間 向後5天,5天後
    DateTime plus5Days = dt.plusDays(5);
    String plus5DaysStr = plus5Days.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("plus 5 days: " + plus5DaysStr);

    // 相對當前時間 向後5個小時,5小時後
    DateTime plus5Hours = dt.plusHours(5);
    String plus5HoursStr = plus5Hours.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("plus 5 hours: " + plus5HoursStr);

    // 相對當前時間,向後5分鍾,5分鍾後
    DateTime plus5Minutes = dt.plusMinutes(5);
    String plus5MinutesStr = plus5Minutes.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("plus 5 minutes: " + plus5MinutesStr);

    // 相對當前時間,向前5年,5年前
    DateTime plus5Years = dt.plusYears(-5);
    String plus5YearsStr = plus5Years.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("5 years ago: " + plus5YearsStr);

    // 相對當前時間,向前5個月
    DateTime plusMonths = dt.plusMonths(-5);
    String plusMonthsStr = plusMonths.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("5 month ago: " + plusMonthsStr);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:36,代碼來源:JodaTimeDemo1.java

示例12: createDefaultStartingHours

import org.joda.time.DateTime; //導入方法依賴的package包/類
private static List<ExamStartingHour> createDefaultStartingHours(String roomTz) {
    // Get offset from Jan 1st in order to no have DST in effect
    DateTimeZone zone = DateTimeZone.forID(roomTz);
    DateTime beginning = DateTime.now().withDayOfYear(1).withTimeAtStartOfDay();
    DateTime ending = beginning.plusHours(LAST_HOUR);
    List<ExamStartingHour> hours = new ArrayList<>();
    while (!beginning.isAfter(ending)) {
        ExamStartingHour esh = new ExamStartingHour();
        esh.setStartingHour(beginning.toDate());
        esh.setTimezoneOffset(zone.getOffset(beginning));
        hours.add(esh);
        beginning = beginning.plusHours(1);
    }
    return hours;
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:16,代碼來源:CalendarController.java

示例13: adjustDST

import org.joda.time.DateTime; //導入方法依賴的package包/類
public static DateTime adjustDST(DateTime dateTime, ExternalReservation externalReservation) {
    DateTime result = dateTime;
    DateTimeZone dtz = DateTimeZone.forID(externalReservation.getRoomTz());
    if (!dtz.isStandardOffset(System.currentTimeMillis())) {
        result = dateTime.plusHours(1);
    }
    return result;
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:9,代碼來源:AppUtil.java

示例14: doAdjustDST

import org.joda.time.DateTime; //導入方法依賴的package包/類
private static DateTime doAdjustDST(DateTime dateTime, ExamRoom room) {
    DateTimeZone dtz;
    DateTime result = dateTime;
    if (room == null) {
        dtz = getDefaultTimeZone();
    } else {
        dtz = DateTimeZone.forID(room.getLocalTimezone());
    }
    if (!dtz.isStandardOffset(System.currentTimeMillis())) {
        result = dateTime.plusHours(1);
    }
    return result;
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:14,代碼來源:AppUtil.java

示例15: secondsUntilNextMondayRun

import org.joda.time.DateTime; //導入方法依賴的package包/類
private int secondsUntilNextMondayRun() {
    DateTime now = DateTime.now();
    // Every Monday at 5AM UTC
    int adjustedHours = 5;
    if (!AppUtil.getDefaultTimeZone().isStandardOffset(now.getMillis())) {
        // Have the run happen an hour earlier to take care of DST offset
        adjustedHours -= 1;
    }

    DateTime nextRun = now.withHourOfDay(adjustedHours)
            .withMinuteOfHour(0)
            .withSecondOfMinute(0)
            .withMillisOfSecond(0)
            .plusWeeks(now.getDayOfWeek() == DateTimeConstants.MONDAY ? 0 : 1)
            .withDayOfWeek(DateTimeConstants.MONDAY);
    if (!nextRun.isAfter(now)) {
        nextRun = nextRun.plusWeeks(1); // now is a Monday after scheduled run time -> postpone
    }
    // Case for: now there's no DST but by next run there will be.
    if (adjustedHours == 5 && !AppUtil.getDefaultTimeZone().isStandardOffset(nextRun.getMillis())) {
        nextRun = nextRun.minusHours(1);
    }
    // Case for: now there's DST but by next run there won't be
    else if (adjustedHours != 5 && AppUtil.getDefaultTimeZone().isStandardOffset(nextRun.getMillis())) {
        nextRun = nextRun.plusHours(1);
    }

    Logger.info("Scheduled next weekly report to be run at {}", nextRun.toString());
    // Increase delay with one second so that this won't fire off before intended time. This may happen because of
    // millisecond-level rounding issues and possibly cause resending of messages.
    return Seconds.secondsBetween(now, nextRun).getSeconds() + 1;
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:33,代碼來源:SystemInitializer.java


注:本文中的org.joda.time.DateTime.plusHours方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。