Current Seconds

To get seconds from current time in Bash script, use date command with format that returns only the seconds.

Syntax

The syntax to get seconds from current time is

date +%S
ADVERTISEMENT

Example

In the following script, we take the seconds from current time in variable seconds, and echo it to the standard console.

Example.sh

seconds=$(date +%S)
echo "Seconds : $seconds"

Output

Seconds : 14

Conclusion

In this Bash Tutorial, we have learnt how to get seconds from current date and time in Bash Script using date command.