如何将日期转换为VB.net中的格式化字符串?

问题描述:

在这里,将字符串转换为日期似乎有一百万个问题,但反之亦然。当我使用 mydate.toString 将Date对象转换为字符串时,我得到一个格式为 16/01/2013 13:00:00

There seems to be a million questions here on converting a string to a Date, but not vice-versa. When I convert a Date object to a string using mydate.toString I get a string in the format 16/01/2013 13:00:00.

但是我真正想要的是 2013-01-16 13:00:00 。我看不到在Date对象上的任何功能,为我做这个事情,我需要使用正则表达式吗?

But what I really want is 2013-01-16 13:00:00. I can't see any functions on the Date object that do this for me, do I need to use a regex or something instead?

您可以使用ToString重载。有关详细信息,请查看此页面

You can use the ToString overload. Have a look at this page for more info

所以使用 myDate.ToString(yyyy-MM-dd HH:mm:ss)

或相当的东西