简体   繁体   English

如何在 Mac OS X 中使用 Bash 将 +1 添加到纪元时间?

[英]How do I add +1 to epoch time using Bash in Mac OS X?

I'd like to add +1 to the epoch time conversion.我想在纪元时间转换中添加 +1。 Right now it outputs 1615715999 & 1 separately, but I'd like for the output to be 1615716000 which is epoch time + 1.现在它分别输出1615715999 & 1 ,但我希望 output 为1615716000 ,即纪元时间 + 1。

This is on Mac OSX using BASH, any suggestions?这是在使用 BASH 的 Mac OSX 上,有什么建议吗? Truly appreciate it!!!真心欣赏!!!

epoch_s= date -j -f "%Y-%m-%d %H:%M:%S" "2021-03-14 01:59:59" +%s
    
declare -i epoch_start=$(( $epoch_s + 1 )) 
    
echo $epoch_start 

You're missing the command substitution syntax:您缺少命令替换语法:

epoch_s=$(date -j -f "%Y-%m-%d %H:%M:%S" "2021-03-14 01:59:59" +%s)
#       ^^........................................................^

No spaces are allowed around the = . =周围不允许有空格。

The reason you get the output you see is that the date output is not stored to the variable, it is emitted to stdout.您看到 output 的原因是date output 未存储到变量中,而是发送到标准输出。 Then the epoch_start variable is assigned the value 1 (an unset variable has value zero in bash arithmetic) which gets echoed on the next line.然后将epoch_start变量赋值为 1(未设置的变量在 bash 算术中的值为零),该值在下一行得到回显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM