在C#中使用日期工作 [英] Working with date in C#
问题描述
我有许多公司每个人都有开幕日期和截止日期前:
I have many companies each one have a opening date and a closing date ex :
Company Open Close
A 08.00 22.00 (close in the **same** day)
B 10.00 02.00 (close in the **second** day)
C 14.00 03.00 (close in the **second** day)
在该网页的用户必须看到公司的名单,并显示每一个(打开或关闭)根据当前时间(服务器时间的状态)
On the web page the user must see a list of the companies and show the status of each one (open or close) depending on the current time (SERVER TIME)
问题:
当公司打开和关闭在同一天(A)可以很容易地获取状态
在下面的算法: isOpen会=(NOW>及的OpenTime NOW< ClosingTime)
,但如果该公司的在天开1 和关闭在每日2 (B,C)如果用户查看的页面1.00 B公司会出现关闭(因为(1.00 GT; 10.00 1.00 LT; 02.00)。
为假),但在实时其打开
THE PROBLEM :
when the company open and close in the same day ( A ) it's easy to get the status
in the following algorithm : isOpen = (NOW > OpenTime AND NOW < ClosingTime)
, but if the company open in day 1 and close in day 2 ( B , C ) if the user check the page at 1.00 the company B will appear closed (because (1.00 > 10.00 AND 1.00 < 02.00)
is False ) but in real time its opened.
我怎样才能解决这个问题(当关闭时间日比开幕当天的时间不同)
How can I resolve this issue (when the closing time day is different than the opening time day)
推荐答案
我能想到的最简单的办法是检查是否列出的关闭时间小于开放时间,增加24小时,检查该值
The easiest solution I can think of would be to check if the close time listed is less than the open time and add 24 hours, and check against that value
isOpen = (NOW > OpenTime AND NOW < (ClosingTime < OpeningTime ? ClosingTime + 24.00 : ClosingTime)
这篇关于在C#中使用日期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!