簡體   English   中英

如何將 output 日期和時間從 powershell 到文件

[英]how to output date and time from powershell to a file

我可以在 powershell 中以 yyyy/mm/dd 格式獲取當前日期和時間。 我希望將此 cmd 的 output 放入文本文件中。

目前我運行的命令是

get-date -format yyyy/mm/dd

按預期工作,但是當我嘗試將 output 重定向到文件時,我看到了錯誤

get-date -format yyyy/mm/dd - o test.txt

這個問題可能是微不足道的,因為我是 powershell 的新手

使用外文件

get-date -format yyyy/mm/dd | Out-File -FilePath C:\Date.txt
date -format yyyy/mm/dd >c:\date.txt

覆蓋txt文件^

date -format yyyy/mm/dd >>c:\date.txt

在txt文件中追加新行^

更短、更有效的方法

我不確定這是否是最近的變化,但 mm 給了我幾分鍾 - 我不得不使用 MM 幾個月,即

date -format yyyy/MM/dd >> c:\date.txt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM