date to epoch seconds can be achieved by using date command. Below is the script which asks user for an input and convert it to UNIX time format.
#!/bin/bash
read -p “Please enter a date in YYYY-MM-DD format: ” DATE1
echo “The UNIX time for $DATE1 is $(date -d”$DATE1″ +%s)”
Save above file and change the permissions.
chmod +x date2epoch.bash
./date2epoch.bash
-d is used to mention the date to get converted.
+%s is to convert this date to epoch or UNIX time-stamp.
This is the simplest way to get the date converted to UNIX seconds.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018