fin*_*fin 0 windows powershell keyboard-shortcuts plaintext
关于如何以纯文本形式快速将当前月份的日历打印到剪贴板或 Windows 环境中的命令,有什么建议吗?在这里要明确的是,我希望看到完整打印的月份,类似于单击 Windows 任务栏中的时钟时看到的内容。我正在考虑使用轻量级 PowerShell 脚本,或者可能有一些其他预打包的 Windows 应用程序功能可以让我轻松地完成此操作。
尝试一下:
function Get-Calendar($year=(Get-Date).Year,$month=(Get-Date).Month){
$dtfi = New-Object System.Globalization.DateTimeFormatInfo
$AbbreviatedDayNames=$dtfi.AbbreviatedDayNames | ForEach-Object {" {0}" -f $_.Substring(0,2)}
$header= "$($dtfi.MonthNames[$month-1]) $year"
$header=(" "*([math]::abs(21-$header.length) / 2))+$header
$header+=(" "*(21-$header.length))
Write-Host $header -BackgroundColor yellow -ForegroundColor black
Write-Host (-join $AbbreviatedDayNames) -BackgroundColor cyan -ForegroundColor black
$daysInMonth=[DateTime]::DaysInMonth($year,$month)
$dayOfWeek =(New-Object DateTime $year,$month,1).dayOfWeek.value__
$today=(Get-Date).Day
for ($i = 0; $i -lt $dayOfWeek; $i++){Write-Host (" "*3) -NoNewline}
for ($i = 1; $i -le $daysInMonth; $i++)
{
if($today -eq $i){Write-Host ("{0,3}" -f $i) -NoNewline -BackgroundColor red -ForegroundColor white}
else {Write-Host ("{0,3}" -f $i) -NoNewline -BackgroundColor white -ForegroundColor black}
if ($dayOfWeek -eq 6) {Write-Host}
$dayOfWeek = ($dayOfWeek + 1) % 7
}
if ($dayOfWeek -ne 0) {Write-Host}
}
PS> Get-Calendar
January 2013
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4668 次 |
| 最近记录: |