Answers for "shell date get timestamp"

2

get current timestamp shell

// If you want to get unix timestamp, then you need to use:
timestamp=$(date +%s)
Posted by: Guest on September-09-2020
1

bash get timestamp

# put current date as yyyy-mm-dd in $date
# -1 -> explicit current date, bash >=4.3 defaults to current time if not provided
# -2 -> start time for shell
printf -v date '%(%Y-%m-%d)Tn' -1 

# put current date as yyyy-mm-dd HH:MM:SS in $date
printf -v date '%(%Y-%m-%d %H:%M:%S)Tn' -1 

# to print directly remove -v flag, as such:
printf '%(%Y-%m-%d)Tn' -1
# -> current date printed to terminal
Posted by: Guest on November-25-2020

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language