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


Java LocalDateTime.plusSeconds方法代碼示例

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


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

示例1: testSplitLocalDateTime

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test(dataProvider = "directions")
public void testSplitLocalDateTime(boolean ascending) {
    final Duration step = Duration.ofSeconds(1);
    final LocalDateTime start = LocalDateTime.of(2014, 1, 1, 14, 15, 20, 0);
    final LocalDateTime end = start.plusSeconds(10000000 * (ascending ? 1 : -1));
    final Range<LocalDateTime> range = Range.of(start, end, step);
    final List<Range<LocalDateTime>> segments = range.split(100);
    Assert.assertTrue(segments.size() > 1, "There are multiple segments");
    for (int i=1; i<segments.size(); ++i) {
        final Range<LocalDateTime> prior = segments.get(i-1);
        final Range<LocalDateTime> next = segments.get(i);
        Assert.assertEquals(prior.end(), next.start(), "Date connect as expect");
        if (i == 1) Assert.assertEquals(prior.start(), range.start(), "First segment start matches range start");
        if (i == segments.size()-1) {
            Assert.assertEquals(next.end(), range.end(), "Last segment end matches range end");
        }
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:19,代碼來源:RangeSplitTests.java

示例2: testIndexPerformance

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test(dataProvider = "style")
public void testIndexPerformance(boolean parallel) {
    final LocalDateTime start = LocalDateTime.now();
    final LocalDateTime end = start.plusSeconds(1000000);
    final Array<LocalDateTime> dates = Range.of(start, end, Duration.ofSeconds(1)).toArray().shuffle(3);
    final Index<LocalDateTime> index = Index.of(dates);
    final long t1 = System.nanoTime();
    final Index<LocalDateTime> sorted = index.sort(parallel, true);
    final long t2 = System.nanoTime();
    System.out.println("Sorted Index in " + ((t2-t1)/1000000 + " millis"));
    for (int j=1; j<index.size(); ++j) {
        final LocalDateTime d1 = sorted.getKey(j-1);
        final LocalDateTime d2 = sorted.getKey(j);
        if (d1.isAfter(d2)) {
            throw new RuntimeException("Index keys are not sorted");
        } else {
            final int i1 = index.getIndexForKey(d1);
            final int i2 = sorted.getIndexForKey(d1);
            if (i1 != i2) {
                throw new RuntimeException("The indexes do not match between original and sorted");
            }
        }
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:25,代碼來源:IndexSortTests.java

示例3: formatter

import java.time.LocalDateTime; //導入方法依賴的package包/類
public String formatter(String toFormat, String aOrAn, Player plr, VirtualCrate vc, CrateReward rewardHolder, PhysicalCrate ps, Integer amount){
    String formatted = toFormat;
    formatted = formatted.replace("%prefix%",prefix);
    if(aOrAn != null)
        formatted = formatted.replace("%a",aOrAn);
    if(rewardHolder != null) {
        formatted = formatted.replace("%R", rewardHolder.getRewardName());
        formatted = formatted.replace("%r", TextSerializers.FORMATTING_CODE.stripCodes(rewardHolder.getRewardName()));
    }
    if(vc != null) {
        formatted = formatted.replace("%C", vc.displayName);
        formatted = formatted.replace("%c", TextSerializers.FORMATTING_CODE.stripCodes(vc.displayName));
        formatted = formatted.replace("%K",vc.displayName + " Key");
        formatted = formatted.replace("%k",TextSerializers.FORMATTING_CODE.stripCodes(vc.displayName + " Key"));
    }
    if(plr != null) {
        formatted = formatted.replace("%P", plr.getName());
        formatted = formatted.replace("%p", TextSerializers.FORMATTING_CODE.stripCodes(plr.getName()));
        if(vc != null) {
            formatted = formatted.replace("%bal%", vc.getVirtualKeyBalance(plr) + "");
        }
    }
    if(amount != null){
        formatted = formatted.replace("%amount%","" + amount);
    }
    if(ps != null){
        if(ps.vc.getOptions().containsKey("freeCrateDelay")) {
            LocalDateTime lastUsed = ps.vc.lastUsed.get(plr.getUniqueId());
            LocalDateTime minimumWait = lastUsed.plusSeconds((int) ps.vc.getOptions().get("freeCrateDelay"));
            formatted = formatted.replace("%t", "" + (LocalDateTime.now().until(minimumWait, ChronoUnit.SECONDS) + 1));
        }
    }
    return formatted;
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:35,代碼來源:LangData.java

示例4: test_toEpochSecond_afterEpoch

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test
public void test_toEpochSecond_afterEpoch() {
    LocalDateTime ldt = LocalDateTime.of(1970, 1, 1, 0, 0).plusHours(1);
    for (int i = 0; i < 100000; i++) {
        ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_PARIS);
        assertEquals(a.toEpochSecond(), i);
        ldt = ldt.plusSeconds(1);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:10,代碼來源:TCKZonedDateTime.java

示例5: test_plusSeconds_one

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test
public void test_plusSeconds_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate();

    int hour = 0;
    int min = 0;
    int sec = 0;

    for (int i = 0; i < 3700; i++) {
        t = t.plusSeconds(1);
        sec++;
        if (sec == 60) {
            min++;
            sec = 0;
        }
        if (min == 60) {
            hour++;
            min = 0;
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:28,代碼來源:TCKLocalDateTime.java

示例6: test_plusSeconds_fromZero

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test(dataProvider="plusSeconds_fromZero")
public void test_plusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.plusSeconds(seconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:TCKLocalDateTime.java

示例7: computeFirstResetTime

import java.time.LocalDateTime; //導入方法依賴的package包/類
protected static LocalDateTime computeFirstResetTime(LocalDateTime baseTime, int time, TimeUnit unit) {
    if (unit != TimeUnit.SECONDS && unit != TimeUnit.MINUTES && unit != TimeUnit.HOURS && unit != TimeUnit.DAYS) {
        throw new IllegalArgumentException();
    }
    LocalDateTime t = baseTime;
    switch (unit) {
        case DAYS:
            t = t.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
            break;
        case HOURS:
            if (24 % time == 0) {
                t = t.plusHours(time - t.getHour() % time);
            } else {
                t = t.plusHours(1);
            }
            t = t.withMinute(0).withSecond(0).withNano(0);
            break;
        case MINUTES:
            if (60 % time == 0) {
                t = t.plusMinutes(time - t.getMinute() % time);
            } else {
                t = t.plusMinutes(1);
            }
            t = t.withSecond(0).withNano(0);
            break;
        case SECONDS:
            if (60 % time == 0) {
                t = t.plusSeconds(time - t.getSecond() % time);
            } else {
                t = t.plusSeconds(1);
            }
            t = t.withNano(0);
            break;
    }
    return t;
}
 
開發者ID:alibaba,項目名稱:jetcache,代碼行數:37,代碼來源:DefaultCacheMonitorManager.java

示例8: weixinAccessToken

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * @Description: 獲取微信token
 * @return    
 * @return PageData    
 * @throws
 */
@RequestMapping(value = "/weixinAccessToken")
@ResponseBody
public PageData weixinAccessToken() {
	try {
		ValueOperations<String, Object> redisOpt = redisTemplate.opsForValue();
		if(redisTemplate.hasKey("WEIXINACCESSTOKEN")){
			return WebResult.requestSuccess(redisOpt.get("WEIXINACCESSTOKEN"));
		}else{
			LocalDateTime localTime=LocalDateTime.now();
			HashMap pd=new HashMap();
			pd.put("grant_type", "client_credential");
			pd.put("appid", weixinAppid);
			pd.put("secret", weixinSecret);
			String info=HttpUtils.httpGet(weixinTockenUrl, pd, null);
			PageData tokenPd=JSON.parseObject(info, PageData.class);
			if(tokenPd.containsKey("access_token")){
				int expiressIn=(int)tokenPd.get("expires_in");
				localTime=localTime.plusSeconds(expiressIn);
				tokenPd.put("expires_in", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(localTime));
				redisOpt.set("WEIXINACCESSTOKEN",tokenPd, expiressIn, TimeUnit.SECONDS);
				return WebResult.requestSuccess(tokenPd);
			}else{
				return WebResult.requestFailed(505, "請求token失敗,請聯係管理員", null);
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
		return WebResult.requestFailed(400, "係統錯誤,請聯係管理員", null);
	}
}
 
開發者ID:noseparte,項目名稱:Spring-Boot-Server,代碼行數:37,代碼來源:AppUserLoginRestful.java

示例9: testClacPlus

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * 時間運算,計算完成後會返回新的對象,並不會改變原來的時間
 */
@Test
public void testClacPlus() {
    LocalDateTime ldt = LocalDateTime.now();

    System.out.println(ldt);

    // 加: 天
    LocalDateTime day = ldt.plusDays(1);
    System.out.println("day: " + day);

    // 加: 小時
    LocalDateTime hours = ldt.plusHours(1);
    System.out.println("hours: " + hours);

    // 加: 分鍾
    LocalDateTime minutes = ldt.plusMinutes(1);
    System.out.println("minutes: " + minutes);

    // 加: 月
    LocalDateTime months = ldt.plusMonths(1);
    System.out.println("months: " + months);

    // 加: 納秒
    LocalDateTime nanos = ldt.plusNanos(1);
    System.out.println("nanos: " + nanos);

    // 加: 秒
    LocalDateTime seconds = ldt.plusSeconds(1);
    System.out.println("seconds: " + seconds);

    // 加: 周
    LocalDateTime weeks = ldt.plusWeeks(1);
    System.out.println("weeks: " + weeks);

    // 加: 年
    LocalDateTime years = ldt.plusYears(1);
    System.out.println("years: " + years);

    System.out.println(ldt);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:44,代碼來源:LocalDateTimeDemo.java

示例10: addSecond

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * 計算 second 秒後的時間
 *
 * @param date   長日期
 * @param second 需要增加的秒數
 * @return 增加後的日期
 */
public static LocalDateTime addSecond(LocalDateTime date, int second) {
    return date.plusSeconds(second);
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:11,代碼來源:DateUtils.java


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