- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
因此,我在需要仅格式化给定 TimeInterval
的纳秒数的情况下使用 DateComponentsFormatter
。问题是它没有按预期工作,或者我在这里混淆了一些我不知道的东西。
这里有 3 个快速测试来说明我在说什么。
let fooFormatter = DateComponentsFormatter()
fooFormatter.allowedUnits = [.second, .nanosecond]
fooFormatter.unitsStyle = .full
fooFormatter.collapsesLargestUnit = true
fooFormatter.allowsFractionalUnits = true
print(fooFormatter.string(from: 42.42424242424242424242424242424242))
输出:可选(“42 秒”)
。
预期:因为这会折叠“最大单位”(在本例中为秒),所以它应该类似于 (Optional("42.42424242424242424242424242424242 * 1e^9"))
.
let fooFormatter = DateComponentsFormatter()
fooFormatter.allowedUnits = [.second, .nanosecond]
fooFormatter.unitsStyle = .full
fooFormatter.allowsFractionalUnits = true
print(fooFormatter.string(from: 42.42))
输出:可选(“42 秒”)
。
预计:即使没有选择不折叠 .second
,我预计任何接近 (Optional("42 seconds 0.42 * 1e^9 nanoseconds"))
。
let fooFormatter = DateComponentsFormatter()
fooFormatter.allowedUnits = [.nanosecond]
fooFormatter.unitsStyle = .full
fooFormatter.allowsFractionalUnits = true
print(fooFormatter.string(from: 42.424242))
输出:无
。
预期:现在它甚至不会将 TimeInterval
识别为有效 - 当它被定义为可能的最小分数时 - 并且显然预期一切以纳秒为单位。
重要的是要注意我使用了 allowsFractionalUnits = true
,这更令人担忧,因为这种行为在上面给出的输出中也不起作用(参见预期行为 here )。
提前致谢。
最佳答案
DateComponentsFormatter
不支持纳秒。
请参阅 allowedUnits
的文档,不包括纳秒。它说:
The allowed calendar units are:
year
month
weekOfMonth
day
hour
minute
second
Assigning any other calendar units to this property results in an exception.
关于swift - DateComponentsFormatter 和 .nanosecond,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54710104/
因此,我在需要仅格式化给定 TimeInterval 的纳秒数的情况下使用 DateComponentsFormatter。问题是它没有按预期工作,或者我在这里混淆了一些我不知道的东西。 这里有 3
有没有办法将零分配给 std::chrono::nanoseconds 类型的持续时间?我尝试了 duration::zero 但失败了。 最佳答案 有一个zero()功能: std::chrono:
在文件/usr/include/c++/4.8 中的 gcc 4.84 中我们有 namespace std { typedef duration nanoseconds; 为什么纳秒
java.sql.Timestamp 的构造函数是这样的: public Timestamp(long time) { super((time/1000)*1000); nanos =
我写了这样的一次性代码,strconv.Itoa(time.Nanoseconds())。但是,它给我这个错误“不能使用 time.Nanoseconds()(类型 int64)作为函数参数中的类型
在我的代码中我有 Time.current.strftime('%Y%m%d%H%M%S%6N')并测试我是否使用了 Rails TimeHelpers #travel_to 方法。 在测试中: tr
我有一些代码可以打开一个 excel 文件并将其保存为 pandas 数据框,它最初用于 Python 2.7,目前我正试图让它在 Python 3 下工作。 最初,我使用了另一篇文章中@myidea
我尝试过从 std::string 和 long long 进行词法转换。两者都给出零值。有什么想法吗? boost::lexical_cast(value) //value can be of st
我想知道函数花费的毫秒数。我正在像这样使用 chrono: chrono::system_clock::time_point start = chrono::high_resolution_clock
鉴于这个最小的代码示例,我在其中从 std::chrono::nanoseconds 构造了一个 time_point: #include int main() { std::chrono::t
以下代码抛出“越界纳秒时间戳:1452-04-15 00:00:00 ”错误。如果我将日期字符串替换为一些最近的日期,例如 2017-01-01,则相同的代码有效。 df=pd.DataFrame({
我正致力于在OpenSearch中创建仪表板,并且我必须创建一个面板来显示人类可读的持续时间,该持续时间记录为一个大整数,表示以纳秒为单位的总时间。例如:存储在OpenSearch-900000000
我是一名优秀的程序员,十分优秀!