使用PowerShell更改CSV中的日期格式 [英] Change date format in CSV using PowerShell

查看:209
本文介绍了使用PowerShell更改CSV中的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PowerShell的新手,我有一个CSV文件,在这里我需要将2列中的日期格式(如下例所示)更改为dd/mm/yyyy格式.

I'm new to PowerShell and I have a CSV file where I need to change the format of the dates in 2 columns (as shown in the example below) to the format dd/mm/yyyy.

"First Name","Last Name","Employee Number","Course Name","Completion Status","Date_Started","Completion_Date"

Joe,Bloggs,8632,"Test Name",Complete,"26 Nov 2015","26 Nov 2015"

有人知道如何使用PowerShell来实现这一目标吗?

Does anyone know how to achieve this using PowerShell?

推荐答案

您可以尝试以下方法:

Import-Csv D:\temp\test.csv | % {$_.Date_Started = ([datetime]($_.Date_Started)).ToString('dd/MM/yyyy');$_.Completion_Date = ([datetime]($_.Completion_Date)).ToString('dd/MM/yyyy');$_} | Export-Csv 'D:\temp\testBis.csv' -NoTypeInformation

您可以尝试[datetime]::ParseExact(...)解析特殊日期.

You can try [datetime]::ParseExact(...) to parse special dates.

这篇关于使用PowerShell更改CSV中的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆