Skip to content

Instantly share code, notes, and snippets.

@TK50P
Last active March 30, 2026 14:30
Show Gist options
  • Select an option

  • Save TK50P/e21c4f450b614a02030c931d8a85909c to your computer and use it in GitHub Desktop.

Select an option

Save TK50P/e21c4f450b614a02030c931d8a85909c to your computer and use it in GitHub Desktop.
Generate Discord Timestamps locally on your PC
# Discord Timestamp Generator for Windows PowerShell
# Save this as 'discord_ts.ps1'
# You might required to run 'Set-ExecutionPolicy Unrestricted' then press A to use this script
function Get-DiscordTimestamp {
$d = Read-Host "Enter specific date you want (YYYY-MM-DD)"
$t = Read-Host "Enter the time you want, 24-hour format (HH:MM:SS)"
try {
$dt = [datetime]::ParseExact("$d $t", "yyyy-MM-dd HH:mm:ss", $null)
$ts = [int64]([datetimeoffset]$dt).ToUnixTimeSeconds()
Write-Host "`nSelect Discord Format (Preview):" -ForegroundColor Cyan
Write-Host "1) <t:${ts}:t> - $($dt.ToString('t')) (Short Time)"
Write-Host "2) <t:${ts}:T> - $($dt.ToString('T')) (Long Time)"
Write-Host "3) <t:${ts}:d> - $($dt.ToString('d')) (Short Date)"
Write-Host "4) <t:${ts}:D> - $($dt.ToString('D')) (Long Date)"
Write-Host "5) <t:${ts}:f> - $($dt.ToString('f')) (Short Full)"
Write-Host "6) <t:${ts}:F> - $($dt.ToString('F')) (Long Full)"
Write-Host "7) <t:${ts}:R> - (Relative Time)"
Write-Host "8) <t:${ts}> - Default"
$choice = Read-Host "Selection (1-8)"
switch ($choice) {
"1" { $flag = "t" } "2" { $flag = "T" } "3" { $flag = "d" } "4" { $flag = "D" }
"5" { $flag = "f" } "6" { $flag = "F" } "7" { $flag = "R" } Default { $flag = "" }
}
# Fix: Using ${} to prevent ':' from being treated as a drive reference
$result = if ($flag -eq "") { "<t:${ts}>" } else { "<t:${ts}:${flag}>" }
Write-Host "`nDiscord Code: $result" -ForegroundColor Green
$result | Set-Clipboard
Write-Host "(Copied to Windows clipboard!)" -ForegroundColor Yellow
}
catch {
Write-Host "`nError: Invalid format. Use YYYY-MM-DD and HH:MM:SS." -ForegroundColor Red
}
}
Get-DiscordTimestamp
# Discord Timestamp Generator
# Copy below text and paste into .zshrc, compatible with Zsh, macOS, Linux, *nix
# Usage: discord_ts
discord_ts() {
local d t ts choice flag result p_t p_T p_d p_D p_f p_F p_R
read "d?Enter specific date you want (YYYY-MM-DD): "
read "t?Enter the time you want, 24-hour format (HH:MM:SS): "
if [[ "$OSTYPE" == "darwin"* ]]; then
ts=$(date -j -f "%Y-%m-%d %H:%M:%S" "$d $t" "+%s" 2>/dev/null)
# Previews for macOS
p_t=$(date -r $ts "+%I:%M %p")
p_T=$(date -r $ts "+%I:%M:%S %p")
p_d=$(date -r $ts "+%m/%d/%Y")
p_D=$(date -r $ts "+%B %d, %Y")
p_f=$(date -r $ts "+%B %d, %Y at %I:%M %p")
p_F=$(date -r $ts "+%A, %B %d, at %Y %I:%M %p")
else
ts=$(date -d "$d $t" "+%s" 2>/dev/null)
# Previews for Linux/GNU
p_t=$(date -d "@$ts" "+%I:%M %p")
p_T=$(date -d "@$ts" "+%I:%M:%S %p")
p_d=$(date -d "@$ts" "+%m/%d/%Y")
p_D=$(date -d "@$ts" "+%B %d, %Y")
p_f=$(date -d "@$ts" "+%B %d, %Y at %I:%M %p")
p_F=$(date -d "@$ts" "+%A, %B %d, %Y at %I:%M %p")
fi
if [ -z "$ts" ]; then
echo "\nError: Invalid format. Please use YYYY-MM-DD and HH:MM:SS."
return 1
fi
echo "\nSelect Discord Format (Preview):"
echo "1) <t:$ts:t> - $p_t (Short Time)"
echo "2) <t:$ts:T> - $p_T (Long Time)"
echo "3) <t:$ts:d> - $p_d (Short Date)"
echo "4) <t:$ts:D> - $p_D (Long Date)"
echo "5) <t:$ts:f> - $p_f (Short Full)"
echo "6) <t:$ts:F> - $p_F (Long Full)"
echo "7) <t:$ts:R> - (Relative Time)"
echo "8) <t:$ts> - Default"
read "choice?Selection (1-8): "
case $choice in
1) flag="t" ;; 2) flag="T" ;; 3) flag="d" ;; 4) flag="D" ;;
5) flag="f" ;; 6) flag="F" ;; 7) flag="R" ;; *) flag="" ;;
esac
result="<t:$ts${flag:+:$flag}>"
echo "\nDiscord Code: $result"
if [[ "$OSTYPE" == "darwin"* ]]; then echo -n "$result" | pbcopy
elif command -v clip.exe >/dev/null; then echo -n "$result" | clip.exe
elif command -v xclip >/dev/null; then echo -n "$result" | xclip -selection clipboard
fi
echo "(Copied to clipboard!)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment