Compare Unix date and time.
To get Unix time, the command is:
current time:
now=`date +"%T"`
we will get a time like "20:55:01"
now=`date +"%H%M%S"`
we will get a time like "205501"
If we want to compare times, we can not compare the times in the format "%H:%M:%S", we can only compare them in the format "%H%M%S". Otherwise we will get an error Illegal number: 20:59:22
To get Unix date, the command is:
date1=`date +"%m/%d/%Y %H:%M:%S"`
We will get a date in like "5/8/2018 20:55:01"
If we want to get timestamp, we will use:
date2=`date +"%s"`
we will get a unix timestamp.
we can compare dates by its unix timestamp. it seems we can not compare two dates like "5/8/2018 20:55:01". Otherwise we will get an error: Illegal number: 05/08/2018 20:59:22.
No comments:
Post a Comment