我可以使用以下日期和时间:
DateTime now = DateTime.Now;如何以DateTime格式本身分别获取当前的日期和时间?
我不在ASP.net( C# )中使用DateTime选择器对话框。
I am able to get date and time using:
DateTime now = DateTime.Now;How can I get the current date and time separately in the DateTime format itself?
I am not using the DateTime picker dialog box in ASP.NET (C#).
最满意答案
那么您可以使用Today属性获取当天的日期DateTime :
DateTime today = DateTime.Today;或者更一般地,您可以使用Date属性。 例如,如果您希望UTC时间可以使用:
DateTime dateTime = DateTime.UtcNow.Date;这不是很清楚,无论是需要还是不需要,但如果你只是想打印日期,你可以使用:
Console.WriteLine(dateTime.ToString("d"));或使用显式格式:
Console.WriteLine(dateTime.ToString("dd/MM/yyyy"));详细了解标准和自定义日期/时间格式字符串。 根据您的情况,您可能还需要指定文化。
如果你想要一个更具表现力的日期/时间API,它可以让你分享日期的时间,你可能想看看我开始的Noda Time项目。 它还没有准备好生产,但我们很乐意听到你想要做的事情...
Well, you can get just today's date as a DateTime using the Today property:
DateTime today = DateTime.Today;or more generally, you can use the Date property. For example, if you wanted the UTC date you could use:
DateTime dateTime = DateTime.UtcNow.Date;It's not very clear whether that's what you need or not though... if you're just looking to print the date, you can use:
Console.WriteLine(dateTime.ToString("d"));or use an explicit format:
Console.WriteLine(dateTime.ToString("dd/MM/yyyy"));See more about standard and custom date/time format strings. Depending on your situation you may also want to specify the culture.
If you want a more expressive date/time API which allows you to talk about dates separately from times, you might want to look at the Noda Time project which I started. It's not ready for production just yet, but we'd love to hear what you'd like to do with it...
更多推荐
发布评论