本文整理汇总了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");
}
}
}
示例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");
}
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}