如何使用指定的时间来决定运行的方法? [英] How do I use specified time to decide the method to run?

查看:80
本文介绍了如何使用指定的时间来决定运行的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助的是(if语句)如何根据指定的工作日时间确定使用哪种方法(运行进程)。日期是无关紧要的。

如何使用指定的时间来决定使用的方法?

我不需要过程甚至方法的帮助。我需要帮助的是if语句来确定使用哪种方法。



两种方法 AllDocuments GetDocsInLast60Minutes 将根据指定的时间使用。



要求

方法AllDocuments

如果时间是早上8点到9点,则使用AllDocuments方法

如果时间是上午11点 - 上午11:05使用AllDocuments方法

如果时间是1 PM - 1:05 PM使用AllDocuments方法

如果时间是下午3点 - 下午3:05使用AllDocuments方法

如果时间是下午5点 - 5点: 05 PM AllDocuments方法使用





方法GetDocsInLast60Minutes

如果时间是上午9点到下午5点GetDocsInLast60Minutes使用方法



我尝试过:



我不是确定如何处理if语句

What I need help with is (if statements) how to determine which method to use (to run a process) based on specified weekday time. Dates are irrelevant.
How do I use specified time to decide the method to use?
I do not need help with the process or even the methods. All I need help with is if statements to determine which method to use.

The two methods AllDocuments and GetDocsInLast60Minutes will be used based on specified times.

Requirements
Method AllDocuments
If the time is 8 AM to 9 AM AllDocuments method is used
If the time is 11 AM - 11:05 AM AllDocuments method is used
If the time is 1 PM - 1:05 PM AllDocuments method is used
If the time is 3 PM - 3:05 PM AllDocuments method is used
If the time is 5 PM - 5:05 PM AllDocuments method is used


Method GetDocsInLast60Minutes
If the time is 9 AM to 5 PM GetDocsInLast60Minutes method is used

What I have tried:

I am not sure how to go about the if statements

If (time is 8AM to 9AM) Then
Use GetDocsInLast60Minutes 

If (time is between 11 AM and 11:05 AM ) Then
Use AllDocuments
'etc

推荐答案

使用日期时间结构(系统) [ ^ ],可让您获得小时,分钟等。
Use a DateTime Structure (System)[^], which allows you to get hours, minutes etc.


要开始,请使用24小时而不是上午。因此,对于下午1:00到1:05的时间段,在代码中将其表示为13小时0分钟到13小时5分钟。

根据您的描述,您只对小时和小时的部分时间感兴趣。所以问题实际上是当前小时和当前分钟的哪个时段,对吗?这导致我们如何找到当前小时和当前分钟。看看理查德给你的参考链接,你能找到合适的方法吗?

1.使用 DateTime.Now Property [ ^ ]

2.使用DateTime.Hour Property(System) [ ^ ]

3.从当前查找当前分钟日期使用 DateTime.Minute Property(System) [ ^ ]

4.其余的只是数学上的if else语句,例如

To start off, use 24 hours time instead of am pm. So for the time slot of 1:00pm to 1:05pm, express it as 13 hr 0 minute to 13 hr 5 minute in the code.
Based on your description, you are only interested in hour and minute parts of the time. So the question is really which time slot the current hour and current minute in, right? This lead us to how to find the current hour and current minute. Look through the reference link that Richard has given you, can you find the right methods?
1. Find current date using DateTime.Now Property[^]
2. Find current hour from the current date using DateTime.Hour Property (System)[^]
3. Find current minute from current date using DateTime.Minute Property (System)[^]
4. The rest is just maths couple with if else statements, e.g.
Imports System
				
Public Module Module1
	Public Sub Main()
		
		Dim now As Date = Date.Now
		
		Dim hour As Integer = now.Hour
		Dim minute As Integer = now.Minute
		
		Console.WriteLine(hour)
		Console.WriteLine(minute)

		If hour = 13 And minute <= 5  Then
			Console.WriteLine("Run method A")
        Else
            Console.WriteLine("Run method B")
        End If
		
	End Sub
End Module

如果您寻求进一步操纵日期时间,请参阅Richard的链接。学习编码的一种方法是参考文档并试验各种方法。

Refer to the link by Richard if you seek further manipulation of date time. One way to learn coding is to refer to the document and experiment with the various methods.


这篇关于如何使用指定的时间来决定运行的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆