问题描述
我正在尝试使用一种可以由表单访问的服务中的方法,以便我可以使用此方法在日期时间选择器中生成随机日期。它只是不起作用,我有两个DTP称为dtp_Current和dtp_New
这是在表格上访问的,我有两个按钮,说明之前和之后,当在单击之前,您猜测新生成的日期将在当前日期之前,如果您在猜测之后单击它将在当前生成的日期之后。我必须使用服务这样做
public int RandomDate()
是我的意思d喜欢在服务中调用的方法,如何执行此操作,以便在单击after按钮时检查dtp_Current日期以查看dtp_New是否更大
我希望这很有意义
摘要:
有表格和服务参考
需要服务参考在dtp_Current生成随机日期
然后在点击之前或之后在dtp_New中生成一个新日期
然后检查dtp_New是否大于或小于dtp_Current
SAVE ME ORIGINALGRIFF
I'm trying to have a kind of method that is in a service that can be accessed by a form so that I can use this method to generate a random date in a date time picker. It just doesn't work however, I have two DTP's called dtp_Current and dtp_New
This is accessed on a form and I have two buttons that say before and after, when before is clicked you are guessing the newly generated date will be before the current date and if you click after it's guessing it's gonna be after the currently generated date. I have to do this using a service however
public int RandomDate()
is what i'd like the method to be called in the Service, how would I go about doing this so when the after button is clicked it checks dtp_Current date to see if dtp_New is larger
I hope this makes sense
summary:
have a form and a service reference
need service reference to generate a random date in dtp_Current
then when before or after is clicked generate a new date in dtp_New
then to check if dtp_New is larger or smaller than dtp_Current
SAVE ME ORIGINALGRIFF
推荐答案
public static Int64 NextInt64(this Random rand)
{
var buffer = new byte[sizeof(Int64)];
rand.NextBytes(buffer);
return BitConverter.ToInt64(buffer, 0);
}
您可能需要调整一下才能获得合适的值 - 但这仍然是您的日期范围!
You might have to fiddle a bit to get "suitable" values - but that's down to your date range anyway!
这篇关于在服务中生成随机日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!