gpt4 book ai didi

linux - 使用 bash 脚本检查时间戳是否在特定范围内

转载 作者:太空狗 更新时间:2023-10-29 11:28:12 24 4
gpt4 key购买 nike

假设我有一堆时间戳

当我遍历这些时间戳时,

01:23:00
12:34:14
17:09:12
...

我只想包含 08:00:00 到 17:00:00 之间的时间戳

请推荐

最佳答案

你可以做一个简单的字符串比较:

if [[ "$timestamp" > "08:00:00" && "$timestamp" < "17:00:00" ]]

如果你想包含范围的末端,你必须单独测试它,因为 Bash 没有 >=<=字符串运算符:

start="08:00:00"
end="17:00:00"
if [[ "$timestamp" == "$start" ||
"$timestamp" > "$start" && "$timestamp" < "$end" ||
"$timestamp" == "$end" ]]

关于linux - 使用 bash 脚本检查时间戳是否在特定范围内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2905259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com