我有一个包含一天时间的日历和文本箱。 我想创造一个日期,即两者的结合。 我知道,我可以这样做,看一看时间,然后在日历日增加时间,但这似乎非常令人迷惑。
是否有更好的办法?
我有一个包含一天时间的日历和文本箱。 我想创造一个日期,即两者的结合。 我知道,我可以这样做,看一看时间,然后在日历日增加时间,但这似乎非常令人迷惑。
是否有更好的办法?
您可使用Datetime.Add() 方法添加时间。
DateTime date = DateTime.Now;
TimeSpan time = new TimeSpan(36, 0, 0, 0);
DateTime combined = date.Add(time);
Console.WriteLine("{0:dddd}", combined);
如果需要,你也可以通过
或者,你可以考虑采用其他控制措施。 你没有提及你是否使用“双赢”、奖牌或笔记本,但是有各种日期和时间选择控制支持选择日期和时间。
如果你使用两个日期物体,一个是储存日期,另一个是:
var date = new DateTime(2016,6,28);
var time = new DateTime(1,1,1,13,13,13);
var combinedDateTime = date.AddTicks(time.TimeOfDay.Ticks);
这方面的一个例子见。
视你的形式而定(并验证!) 文本箱中的日期,你可以做到:
TimeSpan time;
if (TimeSpan.TryParse(textboxTime.Text, out time))
{
// calendarDate is the DateTime value of the calendar control
calendarDate = calendarDate.Add(time);
}
else
{
// notify user about wrong date format
}
Using https://github.com/FluentDatetime
DateTime dateTime = DateTime.Now;
DateTime combined = dateTime + 36.Hours();
Console.WriteLine(combined);
DateTime newDateTime = dtReceived.Value.Date.Add(TimeSpan.Parse(dtReceivedTime.Value.ToShortTimeString()));
两者兼有。 日间医生也支持抽取时间。
你只是必须改变形式——财产,可能要改变习俗。
旧问题,但图一是我赞同我的解决方案,一是采用单独的日期和时间选择控制,因此,我只需要从一个控制点起,而只是从另一个控制点开始,两者都使用。 这将在案文箱中同样和有时间地发挥作用,尽管你可能使用一个遮掩的文本箱或某种对案文投入的验证。
使用电离层控制器的电离层电离层电离层器,但可以取得这一想法,并与任何电离层物体相同:
var startDateTime = DateTime.Parse($"{dateStart.Value.Date.ToShortDateString()} {tpStart.Value.Value.ToShortTimeString()}");
或者在使用文字箱时:
var startDateTime = DateTime.Parse($"{dateStart.Value.Date.ToShortDateString()} {txtTime.Text}");
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...