本文整理汇总了Java中java.time.ZonedDateTime.plusDays方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.plusDays方法的具体用法?Java ZonedDateTime.plusDays怎么用?Java ZonedDateTime.plusDays使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.plusDays方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: adjust
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public Date adjust(Date date, boolean clear) {
//
Date currDate = null;
if (!this.time || clear) this.prevDate = null;
this.travel = toDateTime(truncatedTo(date, ChronoUnit.SECONDS), zoneId);
this.calendar = toDateTime(truncatedTo(date, ChronoUnit.SECONDS), zoneId);
// +1 direction
ZonedDateTime next = this.travel;
for (int i = 0; i < depth && !isValid(currDate = toDate(next)); i++)
next = next.plusDays(prevDate == null ? 1 : !prevDate.after(currDate) ? 1 : -1);
if (isValid(toDate(next))) {
this.travel = next; this.calendar = next; prevDate = currDate; update(); return toDate(calendar);
}
// -1 direction
ZonedDateTime prev = this.travel;
for (int i = 0; i < depth && !isValid(currDate = toDate(prev)); i++)
prev = prev.plusDays(prevDate == null ? -1 : !prevDate.after(currDate) ? 1 : -1);
if (isValid(toDate(prev))) {
this.travel = prev; this.calendar = prev; prevDate = currDate; update(); return toDate(calendar);
}
return adjust(prevDate);
}
示例2: getDelayBeforeNextPost
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static long getDelayBeforeNextPost() {
ZonedDateTime zonedNow = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault());
ZonedDateTime zonedNext = zonedNow.withHour(Config.POST_HOUR).withMinute(0).withSecond(0);
if(zonedNow.compareTo(zonedNext) > 0) {
zonedNext = zonedNext.plusDays(1);
}
return zonedNext.toInstant().toEpochMilli() - zonedNow.toInstant().toEpochMilli();
}
示例3: computestart
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private static void computestart() {
int startHour = 14;
int startMinute = 10;
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
ZonedDateTime start = now.withHour(startHour).withMinute(startMinute).withSecond(0).withNano(0);
if (start.isBefore(now)) start = start.plusDays(1);
long initialDelay = ChronoUnit.MINUTES.between(now, start);
System.out.println(now);
System.out.println(start);
System.out.println(initialDelay + " -> " + initialDelay/60);
}
示例4: getTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static ZonedDateTime getTime(LocalDate date, String time) {
String[] split = time.split(":");
int hour = Integer.valueOf(split[0]);
boolean addDay = false;
if (hour > 23) {
hour = hour - 24;
addDay = true;
}
ZonedDateTime dateTime = ZonedDateTime.of(date, LocalTime.of(hour, Integer.valueOf(split[1]), Integer.valueOf(split[2])), Configuration.getZoneId());
if (addDay) {
dateTime = dateTime.plusDays(1);
}
return dateTime;
}
示例5: apply
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public Expressie apply(final DatumLiteral datumLiteral, final GetalLiteral getalLiteral) {
Expressie resultaat = NullLiteral.INSTANCE;
if (datumLiteral.isVolledigBekend()) {
final ZonedDateTime dt = datumLiteral.alsDateTime();
resultaat = new DatumLiteral(dt.plusDays(getalLiteral.getWaarde()));
}
return resultaat;
}
示例6: factory_ofInstant_allDaysInCycle
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void factory_ofInstant_allDaysInCycle() {
// sanity check using different algorithm
ZonedDateTime expected = LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0).atZone(ZoneOffset.UTC);
for (long i = 0; i < 146097; i++) {
Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L);
ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
assertEquals(test, expected);
expected = expected.plusDays(1);
}
}
示例7: areInSameTimeFrame
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public boolean areInSameTimeFrame(final Instant instant1, final Instant instant2) {
final ZonedDateTime britishTime = instant1.atZone(BRITISH_TIME_ZONE);
final DayOfWeek britishDay = britishTime.getDayOfWeek();
final ZonedDateTime localBase = britishTime.withHour(0).withMinute(0).withSecond(0).withNano(0);
final ZonedDateTime start;
final ZonedDateTime end;
if (britishDay == SUNDAY) {
if (britishTime.isBefore(localBase.withHour(22))) {
start = localBase;
end = localBase.withHour(22);
} else {
start = localBase.withHour(22);
end = localBase.plusDays(2);
}
} else if (britishDay == MONDAY) {
start = localBase.minusDays(1).withHour(22);
end = localBase.plusDays(1);
} else {
start = localBase;
end = localBase.plusDays(1);
}
return instant2.equals(start.toInstant())
|| (instant2.isAfter(start.toInstant()) && instant2.isBefore(end.toInstant()));
}
示例8: executeBan
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public boolean executeBan(String name, String uuid, String[] args, String banner, Player banned) {
if (!PunishmentManager.ips_byUUID.containsKey(uuid))
return false;
String ip = PunishmentManager.ips_byUUID.get(uuid);
String time = args[1].toLowerCase();
ZonedDateTime endTime = ZonedDateTime.now();
String lengthDisplay = "";
if (args[1].startsWith("perm")) {
endTime = endTime.plusYears(1000);
lengthDisplay = ChatColor.YELLOW + "permanently" + ChatColor.RED + " IP banned";
} else {
int amount = Integer.parseInt(time.replaceAll("[^0-9]", ""));
if (time.endsWith("m")) {
endTime = endTime.plusMinutes(amount);
lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " minute" + (amount != 1 ? "s" : "");
} else if (time.endsWith("h")) {
endTime = endTime.plusHours(amount);
lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " hour" + (amount != 1 ? "s" : "");
} else if (time.endsWith("d")) {
endTime = endTime.plusDays(amount);
lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " day" + (amount != 1 ? "s" : "");
} else if (time.endsWith("w")) {
endTime = endTime.plusWeeks(amount);
lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " week" + (amount != 1 ? "s" : "");
} else {
return false;
}
}
lengthDisplay += ChatColor.RESET;
StringBuilder sb = new StringBuilder();
for (int k = 2; k < args.length; k++) {
sb.append(args[k]);
sb.append(' ');
}
final ZonedDateTime fEndTime = endTime;
String reason = sb.toString().trim();
RScheduler.scheduleAsync(plugin, () -> {
AutoCloseable[] ac_dub2 = SQLManager.prepare("INSERT INTO punishments (name, uuid, ip, type, endTime, reason, giver, startTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ");
PreparedStatement insert_ban = (PreparedStatement) ac_dub2[0];
try {
insert_ban.setString(1, name);
insert_ban.setString(2, uuid);
insert_ban.setString(3, ip);
insert_ban.setString(4, PunishmentType.IPBAN.toString());
insert_ban.setString(5, fEndTime.toString());
insert_ban.setString(6, reason);
insert_ban.setString(7, banner);
insert_ban.setString(8, ZonedDateTime.now().toString());
} catch (Exception e) {
e.printStackTrace();
}
SQLManager.execute(ac_dub2);
SQLManager.close(ac_dub2);
System.out.println("Executed IP ban for " + name + ".");
});
String announce = ChatColor.YELLOW + name + ChatColor.RED + " was " + lengthDisplay + ChatColor.RED + " by " + ChatColor.YELLOW + banner + ChatColor.RED + " for: " + ChatColor.WHITE + ChatColor.BOLD + reason + ChatColor.RED + ".";
RMessages.announce(ChatColor.GRAY + "> " + announce);
if (banned != null && banned.isOnline())
banned.kickPlayer("You were " + lengthDisplay + " by " + banner + " for: " + reason + ".");
return true;
}
示例9: executeMute
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public boolean executeMute(String name, String uuid, String[] args, String muter, Player muted) {
String time = args[1].toLowerCase();
ZonedDateTime endTime = ZonedDateTime.now();
String lengthDisplay = "";
if (args[1].startsWith("perm")) {
endTime = endTime.plusYears(1000);
lengthDisplay = ChatColor.YELLOW + "permanently" + ChatColor.RED + " muted";
} else {
int amount = Integer.parseInt(time.replaceAll("[^0-9]", ""));
if (time.endsWith("m")) {
endTime = endTime.plusMinutes(amount);
lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " minute" + (amount != 1 ? "s" : "");
} else if (time.endsWith("h")) {
endTime = endTime.plusHours(amount);
lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " hour" + (amount != 1 ? "s" : "");
} else if (time.endsWith("d")) {
endTime = endTime.plusDays(amount);
lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " day" + (amount != 1 ? "s" : "");
} else if (time.endsWith("w")) {
endTime = endTime.plusWeeks(amount);
lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " week" + (amount != 1 ? "s" : "");
} else {
return false;
}
}
lengthDisplay += ChatColor.RESET;
StringBuilder sb = new StringBuilder();
for (int k = 2; k < args.length; k++) {
sb.append(args[k]);
sb.append(' ');
}
final ZonedDateTime fEndTime = endTime;
String reason = sb.toString().trim();
RScheduler.scheduleAsync(plugin, () -> {
AutoCloseable[] ac_dub2 = SQLManager.prepare("INSERT INTO punishments (name, uuid, ip, type, endTime, reason, giver, startTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ");
PreparedStatement insert_mute = (PreparedStatement) ac_dub2[0];
try {
insert_mute.setString(1, name);
insert_mute.setString(2, uuid);
insert_mute.setString(3, PunishmentManager.ips_byUUID.containsKey(uuid) ? PunishmentManager.ips_byUUID.get(uuid) : "");
insert_mute.setString(4, PunishmentType.MUTE.toString());
insert_mute.setString(5, fEndTime.toString());
insert_mute.setString(6, reason);
insert_mute.setString(7, muter);
insert_mute.setString(8, ZonedDateTime.now().toString());
} catch (Exception e) {
e.printStackTrace();
}
SQLManager.execute(ac_dub2);
SQLManager.close(ac_dub2);
System.out.println("Executed mute for " + name + ".");
PunishmentManager.checkMute(uuid);
});
String announce = ChatColor.YELLOW + name + ChatColor.RED + " was " + lengthDisplay + ChatColor.RED + " by " + ChatColor.YELLOW + muter + ChatColor.RED + " for: " + ChatColor.WHITE + ChatColor.BOLD + reason + ChatColor.RED + ".";
RMessages.announce(ChatColor.GRAY + "> " + announce);
return true;
}
示例10: executeBan
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public boolean executeBan(String name, String uuid, String[] args, String banner, Player banned) {
String time = args[1].toLowerCase();
ZonedDateTime endTime = ZonedDateTime.now();
String lengthDisplay = "";
if (args[1].startsWith("perm")) {
endTime = endTime.plusYears(1000);
lengthDisplay = ChatColor.YELLOW + "permanently" + ChatColor.RED + " banned";
} else {
int amount = Integer.parseInt(time.replaceAll("[^0-9]", ""));
if (time.endsWith("m")) {
endTime = endTime.plusMinutes(amount);
lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " minute" + (amount != 1 ? "s" : "");
} else if (time.endsWith("h")) {
endTime = endTime.plusHours(amount);
lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " hour" + (amount != 1 ? "s" : "");
} else if (time.endsWith("d")) {
endTime = endTime.plusDays(amount);
lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " day" + (amount != 1 ? "s" : "");
} else if (time.endsWith("w")) {
endTime = endTime.plusWeeks(amount);
lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " week" + (amount != 1 ? "s" : "");
} else {
return false;
}
}
lengthDisplay += ChatColor.RESET;
StringBuilder sb = new StringBuilder();
for (int k = 2; k < args.length; k++) {
sb.append(args[k]);
sb.append(' ');
}
final ZonedDateTime fEndTime = endTime;
String reason = sb.toString().trim();
RScheduler.scheduleAsync(plugin, () -> {
AutoCloseable[] ac_dub2 = SQLManager.prepare("INSERT INTO punishments (name, uuid, ip, type, endTime, reason, giver, startTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ");
PreparedStatement insert_ban = (PreparedStatement) ac_dub2[0];
try {
insert_ban.setString(1, name);
insert_ban.setString(2, uuid);
insert_ban.setString(3, PunishmentManager.ips_byUUID.containsKey(uuid) ? PunishmentManager.ips_byUUID.get(uuid) : "");
insert_ban.setString(4, PunishmentType.BAN.toString());
insert_ban.setString(5, fEndTime.toString());
insert_ban.setString(6, reason);
insert_ban.setString(7, banner);
insert_ban.setString(8, ZonedDateTime.now().toString());
} catch (Exception e) {
e.printStackTrace();
}
SQLManager.execute(ac_dub2);
SQLManager.close(ac_dub2);
System.out.println("Executed ban for " + name + ".");
});
String announce = ChatColor.YELLOW + name + ChatColor.RED + " was " + lengthDisplay + ChatColor.RED + " by " + ChatColor.YELLOW + banner + ChatColor.RED + " for: " + ChatColor.WHITE + ChatColor.BOLD + reason + ChatColor.RED + ".";
RMessages.announce(ChatColor.GRAY + "> " + announce);
if (banned != null && banned.isOnline())
banned.kickPlayer("You were " + lengthDisplay + " by " + banner + " for: " + reason + ".");
return true;
}