问题描述
大家好,
我有monthCalendar工具,我想在日历中选择5个随机日期。这5个随机日期应出现在一个文本框中,以便将其保存到我的数据库(mysql)。
我尝试了什么:
我看过很多论坛,但大多数SelectionRange教程都有开始日期和结束日期。我需要的是在一个文本框中记录5个随机日期。
非常感谢您的回答..
Hello everyone,
I have the monthCalendar tool and I would like to select 5 random dates in the calendar. Those 5 random dates should appear in one textbox in order to save it to my database (mysql).
What I have tried:
I saw many forums but most of the SelectionRange tutorial has a start date and an end date. What I need is to record that 5 random dates inside one textbox.
Thank you so much for your answers..
推荐答案
DateTime GenererateRandomDate()
{
int year = rnd.Next(1900, 9999);
int month = rnd.Next(1, 12);
int day = DateTime.DaysInMonth(year,month);
int Day = rnd.Next(1, day);
DateTime dt = new DateTime(year,month,Day);
return dt;
}
这会产生1个日期,你可以将退货日期存储在列表中然后在文本框中显示列表日期。也许你可以使用string.join将它们组成一个字符串。
希望这有助于
this will generate you 1 date , you can store the returns date in a list and then show the list date in the textbox. Maybe you can use string.join to make them in one string.
Hope this helps
这篇关于如何在monthcalendar中选择多个日期并将其显示在C#的文本框中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!