如何将日期转换为VB.net中的格式化字符串? [英] How to convert a Date to a formatted string in VB.net?

查看:113
本文介绍了如何将日期转换为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)

或相当的东西

这篇关于如何将日期转换为VB.net中的格式化字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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