![](/img/trans.png)
[英]Converting other zone date time format to local date-time format in PowerShell
[英]Converting a string to date-time format
我正在使用 powershell 将 csv 导入到 excel。 我的两列都有以下格式的日期时间:
2019-01-25T19:58:28.000Z
我想将该列转换为以下格式"dd/MM/yyyy h:mm"
我尝试了以下两件事,但都没有奏效: [datetime]::ParseExact($fullinfo.A, "dd/MM/yyyy h:mm", $null)
$excel.Columns.item('b').NumberFormat = "dd/MM/yyyy h:mm"
$fullInfoSheet = $workbook.Worksheets.Item(1)
$fullInfoSheet.cells.item(1,1) = "Column A"
$fullInfoSheet.cells.item(1,2) = "Column B"
$fullinfolist = Import-Csv -Path $csvfullFile -Header A, B
$i = 2
foreach($fullinfo in $fullinfolist)
{
$fullInfoSheet.cells.item($i,1) = [datetime]::ParseExact($fullinfo.A, "dd/MM/yyyy h:mm", $null)
$fullInfoSheet.cells.item($i,2) = $fullinfo.B
$i++
}
$excel.Columns.item('b').NumberFormat = "dd/MM/yyyy h:mm"
这会以您想要的格式生成输出
$InputDate = '2019-01-25T19:58:28.000Z'
get-date $InputDate -Format 'dd/MM/yyyy h:mm'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.