[英]JAVA - Find out how long until an event
我找不到太合適的方法來確定玩家離開了多長時間。
這個想法是他們要求獎勵,然后必須等待 24 小時,這是我的代碼:
event.getChannel().sendMessage("You still have " + Misc.msToString(player.getLastDiscordDaily() - System.currentTimeMillis()) + " until you can claim your reward.").queue();
player.getLastDiscordDaily() 保存為 System.currentTimeMillis()
使用的時間也轉換時間:
public static String msToString(long ms) {
long totalSecs = ms/1000;
long hours = (totalSecs / 3600);
long mins = (totalSecs / 60) % 60;
long secs = totalSecs % 60;
String minsString = (mins == 0)
? "00"
: ((mins < 10)
? "0" + mins
: "" + mins);
String secsString = (secs == 0)
? "00"
: ((secs < 10)
? "0" + secs
: "" + secs);
if (hours > 0)
return hours + " hours, " + minsString + " minutes and " + secsString;
else if (mins > 0)
return mins + " minutes and " + secsString + "seconds.";
else return ":" + secsString;
}
輸出:
您還有:0-3,直到您可以領取獎勵。
異常輸出:
在領取獎勵之前,您還有 X 小時 X 分鍾 X 秒的時間。
固定的:
只需將第一行代碼更改為以下內容:
event.getChannel().sendMessage("You still have " + Misc.msToString((player.getLastDiscordDaily() + 86400000) - System.currentTimeMillis()) + " until you can claim your reward.").queue();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.