我希望当前时间四舍五入到下一个30分钟的间隔。例如:如果我以当前时间为8:33 pm打开应用程序,我希望接下来的30分钟向上舍入时间为9:00 pm。如果当前时间是5月22日晚上11:30,那么下一个汇总时间应该是5月23日上午00点。
我尝试使用下面的代码,但是这给了我最近的四舍五入时间,即晚上8:30。
如何获取下一个汇总日期和时间?
func next30Mins() -> Date {
return Date(timeIntervalSinceReferenceDate: (timeIntervalSinceReferenceDate / 1800.0).rounded(.toNearestOrEven) * 1800.0)
}
答案 0 :(得分:1)
您可以获取日期分钟组成部分,检查其是否等于或大于30,然后返回分钟组成部分等于零的nextDate,否则等于30:
module.exports = { chainWebpack (config, isServer) { } }
import time
def create_logs():
print("Creating log file...")
print("Process [", end="")
for i in range(0,5):
time.sleep(1)
print("#", end="")
logs = open('/home/motya/Desktop/logs_py/logs.txt', 'w')
logs.write("LOGS_ENABLE=1\nUSERNAME=GUEST")
logs.close
for i in range(0,5):
time.sleep(1)
print("#",end="")
print("]\nComplete!\n")
def start_welcome():
create_logs()
print("Welcome!")
start_welcome()