使用(表示自 1970 年 1 月 1 日以來的秒數,表示附加 3 位數字表示毫秒)將 a 轉換DateTime為 unix 約定,給出:%s%L%s%L
DateTime.now.strftime '%s%L'
=> "1656279075654"
我怎樣才能從中得到DateTime回報?
DateTime.strptime('1656279075654', '%s%L')給出一個錯誤,strptime似乎并不%L奇怪。
uj5u.com熱心網友回復:
secs = '1656279075654'.to_f / 1000
DateTime.strptime(secs.to_s, '%s')
或者
DateTime.strptime('1656279075654', '%Q')
( %Q- 自 1970-01-01 00:00:00 UTC 以來的毫秒數)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/496314.html
