python仅使用time库实现多个判断两个时间戳之间关系的操作

python仅使用time库实现多个判断两个时间戳之间关系的操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import time

# tz_count表示当前时区与UTC0时区的时间差(秒)
# 判断两个时间戳是否是同一天
def is_today(t1, t2, tz_count=28800):
if int((int(t1)+int(tz_count))/86400) == int((int(t2)+int(tz_count))/86400):
return True
else:
return False

# 判断一个时间戳是否是另一个时间戳的第二天
def is_tomorrow(today, tomorrow, tz_count=28800):
if int((int(today)+int(tz_count))/86400)+1 == int((int(tomorrow)+int(tz_count))/86400):
return True
else:
return False

# 获取输入时间戳表示的那一天的开始时间戳
def day_start(timestamp, tz_count=28800):
return int((int(timestamp)+int(tz_count))/86400)*86400


# 计算两个时间戳中间差了多少天
def day_between(now, start, tz_count=28800):
a = day_start(int(start)) - day_start(int(int(now)+1))
b = int(a/86400)
return b

#简单测试
if __name__ == '__main__':
print(f"当前时间戳: {int(time.time())}")
print(is_today(1616945885.9678676,1616863085))
print(is_tomorrow(1616935085,1616949485))
print(day_between(time.time(),1616862208))
print(day_start(time.time()))
打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2021-2025 lorzzn
  • 访问人数: | 浏览次数:

      请我喝杯咖啡吧~

      支付宝
      微信