如何获取当前日期(不包括小时和分钟)? [英] How can I get the current date (w/o hour and minutes)?
本文介绍了如何获取当前日期(不包括小时和分钟)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在文档中看到的全部是 Datetime.now()
,但它返回了Timespan,我只需要日期。
All I can see in the documentation is Datetime.now()
but it returns the Timespan, I need just the date.
推荐答案
仅用您需要的部分从现在
创建一个新日期:
Create a new date from now
with only the parts you need:
DateTime now = new DateTime.now();
DateTime date = new DateTime(now.year, now.month, now.day);
这篇关于如何获取当前日期(不包括小时和分钟)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文