The Cookie Machine - Click here to drag window

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

Views: 981β€…    Votes:  2β€…    βœ… Solution
Tags: bash   date   time   epoch  
Link: πŸ” See Original Question on Stack Overflow πŸ”—

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    Favorites:  0
Upload: November 24, 2022    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

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  β‡©