epoch

March 28, 2026 ยท View on GitHub

Print the current Unix epoch timestamp, or perform arithmetic on epochs.

Usage

openGyver epoch [flags]
openGyver epoch [subcommand] [flags]

When invoked without a subcommand, prints the current Unix epoch timestamp.

Global Flags (inherited by all subcommands)

FlagShortTypeDefaultDescription
--json-jboolfalseOutput as JSON (includes epoch in seconds, milliseconds, nanoseconds, and ISO 8601)
--msboolfalseOutput in milliseconds
--usboolfalseOutput in microseconds
--nsboolfalseOutput in nanoseconds
--help-hboolShow help for the command

Default Behavior (no subcommand)

When called without a subcommand, openGyver epoch prints the current Unix epoch timestamp. By default the output is in seconds. Use --ms, --us, or --ns for other precisions.

Examples

# Print current epoch in seconds
openGyver epoch

# Print current epoch in milliseconds
openGyver epoch --ms

# Print current epoch in microseconds
openGyver epoch --us

# Print current epoch in nanoseconds
openGyver epoch --ns

# JSON output (includes all precisions and ISO 8601)
openGyver epoch -j

# Use in a script
TIMESTAMP=$(openGyver epoch)

# Use millisecond epoch for a database timestamp
openGyver epoch --ms

# JSON output piped to jq
openGyver epoch -j | jq '.epoch'

JSON Output Format

{
  "epoch": 1711612800,
  "epoch_ms": 1711612800000,
  "epoch_ns": 1711612800000000000,
  "iso8601": "2024-03-28T12:00:00Z"
}

Subcommands

add

Add hours, minutes, days, weeks, months, or years to an epoch timestamp. Uses the current epoch by default. Use --from to specify a starting epoch in seconds. Multiple duration flags can be combined.

Arguments

ArgumentRequiredDescription
(none)All input is provided via flags

Flags

FlagShortTypeDefaultDescription
--fromint0 (current time)Starting epoch in seconds (default: current time)
--hoursint0Hours to add
--minutesint0Minutes to add
--daysint0Days to add
--weeksint0Weeks to add
--monthsint0Months to add
--yearsint0Years to add

Examples

# Add 2 hours to the current epoch
openGyver epoch add --hours 2

# Add 30 days to the current epoch
openGyver epoch add --days 30

# Combine multiple durations: 7 days and 12 hours
openGyver epoch add --days 7 --hours 12

# Add 3 months to a specific epoch
openGyver epoch add --months 3 --from 1705334400

# Add 1 year and 6 months
openGyver epoch add --years 1 --months 6

# Add 2 weeks, output in milliseconds
openGyver epoch add --weeks 2 --ms

# JSON output
openGyver epoch add --days 90 -j

# Add 45 minutes to a known epoch
openGyver epoch add --minutes 45 --from 1711612800

JSON Output Format

{
  "operation": "add",
  "base_epoch": 1711612800,
  "result_epoch": 1711620000,
  "result_epoch_ms": 1711620000000,
  "result_iso8601": "2024-03-28T14:00:00Z"
}

subtract

Subtract hours, minutes, days, weeks, months, or years from an epoch timestamp. Uses the current epoch by default. Use --from to specify a starting epoch in seconds. Multiple duration flags can be combined.

Arguments

ArgumentRequiredDescription
(none)All input is provided via flags

Flags

FlagShortTypeDefaultDescription
--fromint0 (current time)Starting epoch in seconds (default: current time)
--hoursint0Hours to subtract
--minutesint0Minutes to subtract
--daysint0Days to subtract
--weeksint0Weeks to subtract
--monthsint0Months to subtract
--yearsint0Years to subtract

Examples

# Subtract 2 hours from the current epoch
openGyver epoch subtract --hours 2

# Subtract 30 days from the current epoch
openGyver epoch subtract --days 30

# Combine: 7 days and 12 hours ago
openGyver epoch subtract --days 7 --hours 12

# Subtract 3 months from a specific epoch
openGyver epoch subtract --months 3 --from 1705334400

# Subtract 1 year
openGyver epoch subtract --years 1

# Subtract 2 weeks, output in milliseconds
openGyver epoch subtract --weeks 2 --ms

# JSON output for "24 hours ago"
openGyver epoch subtract --hours 24 -j

# Subtract 15 minutes from a known epoch
openGyver epoch subtract --minutes 15 --from 1711612800

JSON Output Format

{
  "operation": "subtract",
  "base_epoch": 1711612800,
  "result_epoch": 1711605600,
  "result_epoch_ms": 1711605600000,
  "result_iso8601": "2024-03-28T10:00:00Z"
}