如何在Powershell中格式化日期时间 [英] How to format datetime in powershell
本文介绍了如何在Powershell中格式化日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试格式化文件夹的日期时间(一旦它们按降序排序).目前,我的日期时间格式为2014年4月25日,并且我想在2014年4月2日显示此信息,但我不知道如何使用格式
I am trying to format the datetime for my folders once they are sorted into descending order . At the moment I have datetime format like 25-04-2014 and I would like to to get displayed 2th april 2014 I am using this code but dont know how to use the formatting
$sortedContent = $content | Sort-Object LastWriteTime -Descending
推荐答案
您可以将结果传递到格式表,并明确告诉您要使用哪种格式.
You can pipe the result to Format-Table and explicitly tell what format you want to use.
以下是ls的示例:
$format = @{Expression={$_.Mode};Label="Mode";width=10},`
@{Expression={$_.LastWriteTime.ToString("D")};Label="LastWriteTime";width=25},`
@{Expression={$_.Name};Label="Name";width=100}
ls | sort LastWriteTime -descending | format-table $format
当然,您可以在正确的日期格式中使用"ToString"调用.
Of course, you can use the proper date format in the "ToString" call.
这篇关于如何在Powershell中格式化日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文