• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Search

epoch

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

Calculate Epoch Time to Date

June 27, 2019

Here’s how to calculate epoch time using the Linux date command.

# Linux
date --date @1561266781
date -d @1561266781
# MacOS
date -r 1561266781

# Linux date --date @1561266781 date -d @1561266781 # MacOS date -r 1561266781

Output is : Sun Jun 23 05:13:01 UTC 2019

Show current epoch time.

date +%s

date +%s

Output: 1561642643

Filed Under: Cloud Tagged With: calculate, date, epoch, time

  • Home
  • About
  • Search

Copyright © 2023