The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

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?

⇧ Run a specific command with root password prompt even if running as root Using Zenity to maintain configuration file  β‡©