Skip to content

Instantly share code, notes, and snippets.

@ajermakovics
Created June 14, 2020 08:07
Show Gist options
  • Save ajermakovics/c55f0b7dc69f11aa218e4393725381c4 to your computer and use it in GitHub Desktop.
Save ajermakovics/c55f0b7dc69f11aa218e4393725381c4 to your computer and use it in GitHub Desktop.
Date to timestamp (macOS)
#!/bin/bash
# Convert given date to timestamp
# Date format: YYYY-MM-DD (2020-02-28)
# If no argument given use current date
CURDATE=`date +%F`
DATE=${1:-$CURDATE}
echo "Arg/Cur: $DATE"
IFS=-
set $DATE
YEAR=$1
MONTH=$2
DAY=$3
echo "Parsed: $YEAR/$MONTH/$DAY"
echo Date $DATE timestamp:
TS=`date -j $MONTH$DAY$YEAR +"%s"`
echo $TS
echo ${TS}000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment