我正在为员工休假 [英] I am working on leave process for a employee
问题描述
这里我使用两个datetimepicker如果员工从给定的datetimepicker中选择日期我希望减去日期显示在文本框中可以任何人告诉我如何减去
我尝试了什么:
我试过这个,但不知道如何在文本框中显示它点击申请按钮
DateTime startdate;
DateTime enddate;
TimeSpan再版;
startdate = DateTime.Parse(dateTimePicker1.Text)。日期;
enddate = DateTime.Parse(dateTimePicker2.Text)。日期;
remaindate = enddate - startdate;
Here I am using two datetimepicker's if the employee selects the date from the given datetimepicker i want the subtraction of the dates to be displayed in textbox can any one will tell me how to subtract
What I have tried:
I have tried this one but don't know how to display it in textbox by clicking the apply button
DateTime startdate;
DateTime enddate;
TimeSpan remaindate;
startdate = DateTime.Parse(dateTimePicker1.Text).Date;
enddate = DateTime.Parse(dateTimePicker2.Text).Date;
remaindate = enddate - startdate;
推荐答案
你有正确的想法 - 该代码减去两个日期并提供它们之间的差异。
所有你需要做的使用Timespan.ToString将TimeSpan值转换为字符串:
TimeSpan.ToString方法(系统) [ ^ ]这将为您提供天:小时:分钟:seconds.microseconds
它有一个接受格式字符串的重载: TimeSpan.ToString方法(字符串)(系统) [ ^ ],可让您准确选择要显示的内容。
您所要做的就是将该字符串放入文本框中.Text属性。
You have the right idea - that code subtracts two dates and provides the difference between them.
All you need to do is convert the TimeSpan value to a string, using Timespan.ToString:
TimeSpan.ToString Method (System)[^] which will give you "days:hours:minutes:seconds.microseconds"
It has an overload which accepts a format string: TimeSpan.ToString Method (String) (System)[^] which lets you select exactly what to display.
All you have to do is put that string into the textbox.Text property.
这篇关于我正在为员工休假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!