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

查看:35
本文介绍了如何在 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天全站免登陆