• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

Calculate Date to Epoch Time

June 24, 2022

Here’s a script to convert date to epoch time on Mac OS.

#!/bin/bash
if [[ -z $1 ]]; then
  echo "Format: date2epoch.sh 2022/01/01-04:58:06"
else
  echo "$1"; date -j -f date -j -f "%Y/%m/%d-%T" "$1" +"%s"
fi

#!/bin/bash if [[ -z $1 ]]; then echo "Format: date2epoch.sh 2022/01/01-04:58:06" else echo "$1"; date -j -f date -j -f "%Y/%m/%d-%T" "$1" +"%s" fi

Result

$ ./date2epoch.sh 2022/08/31-22:00:00
2022/08/31-22:00:00
1661997600

$ ./date2epoch.sh 2022/08/31-22:00:00 2022/08/31-22:00:00 1661997600

Filed Under: Linux Tagged With: conversion, date, epoch

Search This Website

Subscribe Via Email

  • Home
  • About
  • Archives

Copyright © 2023