![](/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.