本文整理汇总了Java中java.time.ZonedDateTime.plusWeeks方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.plusWeeks方法的具体用法?Java ZonedDateTime.plusWeeks怎么用?Java ZonedDateTime.plusWeeks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.plusWeeks方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDelay
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static long getDelay() {
ZonedDateTime nextDate = ZonedDateTime.now()
.with(DayOfWeek.SUNDAY)
.withHour(12)
.withMinute(0)
.withSecond(0);
if(nextDate.isBefore(ZonedDateTime.now())) {
nextDate = nextDate.plusWeeks(1);
}
return TimeUtils.getMillisUntil(nextDate.toInstant());
}
示例2: test_plusWeeks
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_plusWeeks() {
LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
ZonedDateTime test = base.plusWeeks(1);
assertEquals(test, ZonedDateTime.of(ldt.plusWeeks(1), ZONE_0100));
}
示例3: test_plusWeeks_zero
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_plusWeeks_zero() {
LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
ZonedDateTime test = base.plusWeeks(0);
assertEquals(test, base);
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}