如何获取当前日期(不含小时和分钟)? [英] How can I get the current date (w/o hour and minutes)?

查看:26
本文介绍了如何获取当前日期(不含小时和分钟)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文档中只能看到 DateTime.now() 但它也返回时间跨度,我只需要日期.

All I can see in the documentation is DateTime.now() but it returns the Timespan also, and I need just the date.

推荐答案

now 创建一个新日期,只包含您需要的部分:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆