Views:
1,185β
Votes: 2β
β
Solution
Tags:
bash
date
time
epoch
Link:
π See Original Question on Stack Overflow β§ π
URL:
https://stackoverflow.com/q/42521666
Title:
Convert today's HH:MM am/pm to epoch in Bash
ID:
/2017/03/01/Convert-today_s-HH_MM-am_pm-to-epoch-in-Bash
Created:
March 1, 2017
Edited: October 17, 2017
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
I have two variables $sunrise
=β7:23 amβ and $sunset
=β6:10 pmβ. I need to convert both of them to todayβs epoch equivalent as in:
secSunrise=($date ... "$sunrise" ... +"%s")
secSunset=$(date ... "$sunset" ... +"%s")
The only thing Iβve figured out so far is doing it with current date-time:
$ secNow=$(date +"%s")
$ echo $secNow
1488331535
How to square this circle and plug the HH:MM am/pm
12-hour formatted variable into the date
command?