没有时间的当前日期 [英] Current date without time

查看:72
本文介绍了没有时间的当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取当前日期却没有时间?我正在尝试将日期从"dd.mm.yyyy"格式转换为"yyyy-MM-dd",因为 DateTime.Now 也会返回时间,所以我得到了一个错误(当我尝试执行以下操作时,无法将字符串识别为有效的DateTime .)

How can I get the current date but without the time? I am trying to convert the date from the "dd.mm.yyyy" format to "yyyy-MM-dd", because DateTime.Now returns the time too, I get an error (String was not recognized as a valid DateTime.) when I try to do the following.

string test = DateTime.ParseExact(DateTime.Now.ToString(), "dd.MM.yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd");

推荐答案

String test = DateTime.Now.ToString("dd.MM.yyy");

这篇关于没有时间的当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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