如何使用日期时间计算夜间时间?

如何使用日期时间计算夜间时间?

问题描述:

Hey Codeproject,



我已经知道一天有86400秒,我想让86400的颜色更黑一些标记。



所以,我开始做以下事情:



Hey Codeproject,

I've already figured out that there's 86400 seconds in a day, and I'd like to make a color more black towards the 86400 mark.

So, I started by doing the following:

// pseudo code
// Color * 0f = Completely Transparent
// BackgroundColor = Color
Color.Black * (1f / 86400f * DateTime.TotalSeconds)





问题是,当它到达午夜时,总秒数将重置为0,因为新的一天开始了。那时候还是晚上想的。



有没有人知道如何解决这个问题?



最好的问候,

- 11841791



我的尝试:





The problem is though, the moment it hits midnight, the total seconds will be reset to 0, since a new day started. It's still night thought at that point.

Does anyone have an idea on how to fix this?

Best Regards,
- 11841791

What I have tried:

// pseudo code
// Color * 0f = Completely Transparent
// BackgroundColor = Color
Color.Black * (1f / 86400f * DateTime.TotalSeconds)

而不是使用午夜以来的秒数。

使用12点左右(之前或之后)的秒数。

Rather than using the number of seconds since midnight.
Use the number of seconds around (before or after) 12 o clock.
abs((86400/2)-DateTime.TotalSeconds)



[更新]

注意我的公式的最大结果是 43200