Last active
December 21, 2025 20:41
-
-
Save trackd/adbf17d43e85bf910ad0280803c26eb4 to your computer and use it in GitHub Desktop.
Discord time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ConvertTo-DiscordTime { | |
| <# | |
| .SYNOPSIS | |
| Converts a DateTime to a Discord formatted timestamp. | |
| ShortTime => 21:38 | |
| MediumTime => 21:38:23 | |
| ShortDate => 12/21/25 | |
| LongDate => December 21, 2025 | |
| LongDateShortTime => December 21, 2025 at 21:38 | |
| FullDateShortTime => Sunday, December 21, 2025 at 21:38 | |
| ShortDateShortTime => 12/21/25, 21:38 | |
| ShortDateMediumTime => 12/21/25, 21:38:23 | |
| Relative => 3 minutes ago | |
| .NOTES | |
| format: | |
| <t:UnixTimeSecond:R> | |
| e.g. | |
| <t:1766069340:R> | |
| .EXAMPLE | |
| 'ShortTime', 'MediumTime', 'ShortDate', 'LongDate', 'LongDateShortTime', 'FullDateShortTime', 'ShortDateShortTime', 'ShortDateMediumTime', 'Relative' | ForEach-Object { | |
| '{0} => {1}' -f $_, (ConvertTo-DiscordTime (Get-Date) $_) | |
| } | |
| .LINK | |
| https://discord.com/developers/docs/reference#message-formatting-timestamp-styles | |
| #> | |
| [CmdletBinding()] | |
| [Alias('To-DiscordTime', 'DiscordTime')] | |
| param( | |
| [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] | |
| [Alias('Date')] | |
| [DateTime] $DateTime, | |
| [Parameter(ValueFromPipelineByPropertyName)] | |
| [ValidateSet('ShortTime', 'MediumTime', 'ShortDate', 'LongDate', 'LongDateShortTime', 'FullDateShortTime', 'ShortDateShortTime', 'ShortDateMediumTime', 'Relative')] | |
| [String] $Format = 'FullDateShortTime' | |
| ) | |
| begin { | |
| $ht = @{ | |
| ShortTime = 't' | |
| MediumTime = 'T' | |
| ShortDate = 'd' | |
| LongDate = 'D' | |
| LongDateShortTime = 'f' | |
| FullDateShortTime = 'F' | |
| ShortDateShortTime = 's' | |
| ShortDateMediumTime = 'S' | |
| Relative = 'R' | |
| } | |
| } | |
| process { | |
| $DTOffset = [DateTimeOffset]$DateTime | |
| '<t:{0}:{1}>' -f $DTOffset.ToUnixTimeSeconds(), $ht[$Format] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome, thanks @trackd