我正在努力轉換日期/時間值。問題是時間組件包含小數秒,并且字串中還有其他字符應該被過濾掉。
當前資料/時間變數的格式為:
2018-12-30T18:03:23.400Z
我正在尋找的結果是:
2018-12-30 18:03:23.4
我嘗試從這些堆疊溢位問題中重現: Parse string with additional characters in format to Date and Convert a large string to dates, but the dates have a non numeric character
但我無法讓他們作業。
uj5u.com熱心網友回復:
這個anytime包(我寫的)旨在消除過時(和日期時間)決議的痛苦。它涵蓋了您的格式(關于傳入時區的一個警告,很少有決議器涵蓋),因為它涵蓋了其他格式:
> library(anytime)
> anytime("2018-12-30T18:03:23.400Z")
[1] "2018-12-30 18:03:23.4 CST"
>
如果您只想顯示一位數字,請明確選擇。我告訴我的 R 會話默認為六個:
> Sys.time()
[1] "2022-10-24 16:41:34.745706 CDT"
> options(digits.secs=1)
> Sys.time()
[1] "2022-10-24 16:41:49.9 CDT"
>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/521369.html
