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.
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
-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)
- 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
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018
- Online training on Linux Bash shell scripting - February 8, 2018