簡體   English   中英

將字符串轉換為日期時間格式

[英]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.

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