我有一个包含3个字符串变量的一个项目。
I have a project that contain 3 string variables.
问题是,我不想手动指定的日期。正如你可以在下面我举的例子看(工作示例),我需要指定的日期,但有没有办法让它的起始日期有时间00:00:00,结束日期有时间23时59分: ?59
The problem is that I don't want to manually specify the dates. As you can see in my example below (a working example), I need to specify the dates, but is there a way to make it that the from date has time 00:00:00 and the end date has time 23:59:59?
string DateFormatStr = "MM/dd/yy hh:mm:ss tt"; string DateFormatFrom = "12/04/14 00:00:00"; string FilloutDateTo = "12/04/14 23:59:59";
所以,我想系统时间从日期和开始日期承认尊重 formatStr 变量。
感谢
推荐答案如果我理解正确的话,你可以使用的 DateTime.Today 属性喜欢;
If I understand correctly, you can use DateTime.Today property like;
var dt1 = DateTime.Today; var dt2 = DateTime.Today.AddDays(1).AddSeconds(-1);和使用的 则DateTime.ToString() 进行格式化喜欢;
and use DateTime.ToString() to format them like;
var DateFormatFrom = dt1.ToString("MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture); var FilloutDateTo = dt2.ToString("MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
结果会;
Results will be;
12/04/2014 00:00:00 12/04/2014 23:59:59您使用的 HH 格式说明但它是12小时制。使用 HH 格式说明,而不是它是24小时制。而且,由于你的结果字符串没有任何AM / PM指示,你并不需要使用 TT 格式说明。
You used hh format specifier but it is for 12-hour clock. Use HH format specifier instead which is for 24-hour clock. And since your result strings doesn't have any AM/PM designator, you don't need to use tt format specifier.
更多推荐
在C#中的DateTime字符串格式
发布评论