Skip to content

Commit

Permalink
tip: Add DateTime Format tip
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlydog committed Mar 4, 2024
1 parent a1a4eb8 commit 12da21e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$tip = [tiPS.PowerShellTip]::new()
$tip.CreatedDate = [DateTime]::Parse('2024-03-04')
$tip.Title = 'Get filesystem friendly DateTime with Get-Date'
$tip.TipText = @'
It's common to use a date timestamp in a filename for things like log files. The default output of Get-Date includes characters that are not valid for the filesystem, such as colons. You can use the -Format parameter to specify a custom format, or leverage the built-in FileDate and FileDateTime formats that are filesystem friendly.
'@
$tip.Example = @'
PS> Get-Date
Monday, March 4, 2024 9:43:18 AM
PS> Get-Date -Format 'yyyy-MM-dd_HH-mm-ss'
2024-03-04_09-43-37
PS> Get-Date -Format FileDate
20240304
PS> Get-Date -Format FileDateTime
20240304T0943556270
PS> Get-Date -Format FileDateTimeUniversal
20240304T1544081746Z
'@
$tip.Urls = @(
'https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-date?view=powershell-7.4#-format'
)
$tip.Category = [tiPS.TipCategory]::NativeCmdlet # Community, Editor, Module, NativeCmdlet, Performance, Security, Syntax, Terminal, or Other.
#$tip.ExpiryDate = [DateTime]::Parse('2024-10-30') # Optional. If the tip is not relevant after a certain date, set the expiration date. e.g. Announcing a conference or event.

# Category meanings:
# Community: Social events and community resources. e.g. PowerShell Summit, podcasts, etc.
# Editor: Editor tips and extensions. e.g. VSCode, ISE, etc.
# Module: Modules and module tips. e.g. PSScriptAnalyzer, Pester, etc.
# NativeCmdlet: Native cmdlet tips. e.g. Get-Process, Get-ChildItem, Get-Content, etc.
# Performance: Tips to improve runtime performance. e.g. foreach vs ForEach-Object, ForEach-Object -Parallel, etc.
# Security: Security tips. e.g. ExecutionPolicy, Constrained Language Mode, passwords, etc.
# Syntax: Syntax tips. e.g. splatting, pipeline, etc.
# Terminal: Terminal shortcuts and tips. e.g. PSReadLine, Windows Terminal, ConEmu, etc.
# Other: Tips that don't fit into any of the other categories.
14 changes: 13 additions & 1 deletion src/tiPS/PowerShellTips.json
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,21 @@
"TipText": "VS Code is the preferred IDE to write and run PowerShell scripts. If the workspace has a .vscode\\launch.json file configured though, pressing F5 may run the application instead of running the PowerShell script that you have in focus. To force VS Code to always run the PowerShell script in focus, you can add a keyboard shortcut to the keybindings.json file.\r\n\r\nTo add the keybinding, press Ctrl+Shift+P to open the Command Palette, open \"Preferences: Open Keyboard Shortcuts (JSON)\", and then add the following JSON to the keybindings.json file:\r\n\r\n{\r\n \"key\": \"f5\",\r\n \"command\": \"PowerShell.Debug.Start\",\r\n \"when\": \"editorTextFocus && debugState == 'inactive' && editorLangId == 'powershell'\"\r\n}",
"Example": "",
"Urls": [
"https://coryknox.dev/posts/2024/run-powershell-no-mater-what/"
"https://coryknox.dev/posts/2024/run-powershell-no-mater-what/",
"https://twitter.com/CoryKnox/status/1762253942753493451"
],
"Category": 1,
"ExpiryDate": "9999-12-31T23:59:59.9999999"
},
{
"CreatedDate": "2024-03-04T00:00:00",
"Title": "Get filesystem friendly DateTime with Get-Date",
"TipText": "It's common to use a date timestamp in a filename for things like log files. The default output of Get-Date includes characters that are not valid for the filesystem, such as colons. You can use the -Format parameter to specify a custom format, or leverage the built-in FileDate and FileDateTime formats that are filesystem friendly.",
"Example": "PS> Get-Date\r\nMonday, March 4, 2024 9:43:18 AM\r\n\r\nPS> Get-Date -Format 'yyyy-MM-dd_HH-mm-ss'\r\n2024-03-04_09-43-37\r\n\r\nPS> Get-Date -Format FileDate\r\n20240304\r\n\r\nPS> Get-Date -Format FileDateTime\r\n20240304T0943556270\r\n\r\nPS> Get-Date -Format FileDateTimeUniversal\r\n20240304T1544081746Z",
"Urls": [
"https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-date?view=powershell-7.4#-format"
],
"Category": 3,
"ExpiryDate": "9999-12-31T23:59:59.9999999"
}
]

0 comments on commit 12da21e

Please sign in to comment.