C# 将时间分成小时块
我需要一些帮助来将两个日期时间分成它们之间的小时间隔。
这是与“付费”数据一起使用的,因此它需要非常准确。我需要打卡上班和下班,并将它们分成小时间隔。
示例:
打卡 = 5/25/2011 1:40:56PM
打卡 = 5/25/2011 6:22:12PM
我需要看起来像:
5/25 /2011 1:40:56PM
5/25/2011 2:00:00PM
5/25/2011 3:00:00PM
5/25/2011 4:00:00PM
5/25/2011 5:00:00PM
5/25 /2011 6:00:00PM
5/25/2011 6:22:12PM
然后我计划根据“差异”表检查这些时间,看看他们是否应该有一个新的支付代码。但我稍后会担心支付代码。
有什么帮助分散时间吗?更喜欢 C#,但我也可以访问 MSSQL2000(这是我们拉原始时代的地方)
I am in need of some assistance in getting 2 datetimes to split into the hour intervals between them.
This is working with 'pay' data, so it needs to be very accurate. I need to take clockin and clockout, and split them into hour intervals.
Example:
clockin = 5/25/2011 1:40:56PM
clockout = 5/25/2011 6:22:12PM
I need that to look like:
5/25/2011 1:40:56PM
5/25/2011 2:00:00PM
5/25/2011 3:00:00PM
5/25/2011 4:00:00PM
5/25/2011 5:00:00PM
5/25/2011 6:00:00PM
5/25/2011 6:22:12PM
I then plan to check those times against a 'differential' table to see fi they should have a new paycode. But I'll worry about the paycode later.
Any help splitting out the times? Prefer C#, but I also have access to MSSQL2000 (which is where we pull the original times)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
像这样的事情怎么样?
这使用 迭代器块 但它可以很容易地重写以返回一个列表。
使用示例:
输出:
更新:LukeH< /a> 很聪明地建议您还应该复制 DateTimeKind。如果您计划稍后将日期时间与本地时间相互转换,这确实是一个明智之举。
How about something like this?
This uses iterator blocks but it could easily be rewritten to return a list instead.
Example use:
Output:
Update: LukeH was clever enough to suggest that you should also copy the DateTimeKind. This is indeed a smart move if you're planning on converting the datetimes to/from local time later on.
我认为这样的事情应该有效:
I think something like this should work:
我会这样做:
像这样使用它:
I would do this:
Use it like this: