3 Ways to Get Unix Timestamps in Shell: Seconds and Milliseconds

Learn 3 simple methods to get Unix timestamps (seconds or milliseconds) in Shell for scripts and Discord. Verify results with our free tool!

3 Ways to Get Unix Timestamps in Shell: Seconds and Milliseconds

Shell scripting is ideal for automation, and getting Unix timestamps is a common task. This guide covers 3 methods to generate timestamps in seconds or milliseconds, perfect for scripts and Discord, with DevUtils’ free tool for validation.

Unix Timestamp Overview

A Unix timestamp counts seconds or milliseconds since January 1, 1970, 00:00:00 UTC. Seconds are 10 digits (e.g., 1694870400), milliseconds are 13 digits (e.g., 1694870400000) (Keywords: unix timestamp in seconds or milliseconds).

Method 1: Using date Command

Method 2: Using bc for Precision

For systems lacking %N:

echo "$(date +%s) * 1000 + $(date +%N)/1000000" | bc
# Output: 1694870400000

Method 3: Generating Discord Timestamps

Input Shell timestamps into DevUtils’ Timestamp Converter to create Discord formats:

Verification and Applications

DevUtils’ tool verifies Shell timestamps:

Shell offers versatile timestamp methods, and DevUtils’ free Timestamp Tool ensures accuracy. Try it now to enhance your scripting!