我想要一个可以转换为is8601格式的时间对象:“2022-10-01T22:38:45.100Z”
我试过这个:
Time.utc(2022, 10, 1, 22, 38, 45, 100).in_time_zone.iso8601(3)
但这给了我“2022-10-01T22:38:45.000Z”,而不是“2022-10-01T22:38:45.100Z”毫秒信息不知何故消失了。它永远是000
我做错了什么?谢谢
5f0d552i1#
你的比分是三个零:
>> Time.utc(2022, 10, 1, 22, 38, 45, 100) => 2022-10-01 22:38:45.0001 UTC # ^ # NOTE: These are microseconds. # aka `usec` >> Time.utc(2022, 10, 1, 22, 38, 45, 100).usec => 100
乘以1000才能进入毫秒范围:
>> Time.utc(2022, 10, 1, 22, 38, 45, 123_000).in_time_zone.iso8601(3) => "2022-10-01T22:38:45.123Z"
1条答案
按热度按时间5f0d552i1#
你的比分是三个零:
乘以1000才能进入毫秒范围: