获取一天中的时间段(小时/半小时/刻钟)
有什么办法可以每小时和一天中的其他时段下载吗? 我指的是列表形式的结果。
[
"00:00", // start of the day e.q 14.03
"01:00",
"02:00",
....
"23:00",
"00:00 // end of the day e.q 14.03
]
,
[
"00:00", // start of the day e.q 14.03
"00:30",
"01:00"
"01:30"
....
"00:00 // end of the day e.q 14.03
]
14.03
[
"00:00", // start of the day e.q 14.03
"00:15",
"00:30"
"00:45"
"01:00"
....
"00:00 // end of the day e.q 14.03
]
出于示例目的
表示 3 月 14 日。当然,可以手动添加它,但这不是一个特别优雅的解决方案。是否可以在不明确声明常量作为每小时值的情况下做到这一点? 最好的解决方案是不使用循环和 if else 结构的函数。
我还没有找到这种解决方案的实现。我自己也花了一个小时在这上面但没有成功。我需要它来实现一个功能,从这样的 eq 小时列表中创建一个 Map 或一个对列表:
[
"00:00 - 01:00",
"01:00 - 02:00",
"02:00 - 03:00 "
//.......
"23:00 - 00:00"
]
有人有机会实现这样的问题并且能够提供帮助吗?
Is there any way to download every hour and another period of the day?
I mean exactly the result in the form of a list.
[
"00:00", // start of the day e.q 14.03
"01:00",
"02:00",
....
"23:00",
"00:00 // end of the day e.q 14.03
]
and
[
"00:00", // start of the day e.q 14.03
"00:30",
"01:00"
"01:30"
....
"00:00 // end of the day e.q 14.03
]
and
[
"00:00", // start of the day e.q 14.03
"00:15",
"00:30"
"00:45"
"01:00"
....
"00:00 // end of the day e.q 14.03
]
14.03 means March 14 for the sake of the example.
Of course it is possible to add this manually, but it would not be a particularly elegant solution. Is it possible to do it without explicitly declaring constants as values of each hour ?
The best solution would be a function without using loops and if else constructions.
I have not yet been able to find an implementation of such a solution. I myself also spend another hour on this without success. I need it to implement a functionality that creates a Map or a list of pairs from a list of such e.q hours:
[
"00:00 - 01:00",
"01:00 - 02:00",
"02:00 - 03:00 "
//.......
"23:00 - 00:00"
]
Has anyone had occasion to implement such a problem and would be able to help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写一个函数来生成
Sequence
,如下所示:然后您就拥有了可以与
toString()
或.format( )
和一些 DateTimeFormatter 来按照您喜欢的方式格式化它们。您可以使用 zipWithNext() 来创建时间范围。请注意,我使用完全限定的 java.time.Duration 来避免与 Kotlin 标准库 Duration 类发生冲突。
You could write a function to generate a
Sequence<LocalTime>
like this:Then you have all the LocalTimes you can use with
toString()
or with.format()
and some DateTimeFormatter to format them how you like. You can usezipWithNext()
to create the time ranges.Note, I'm using fully qualified
java.time.Duration
to avoid conflicts with the Kotlin standard library Duration class.