How to convert a Date to a formatted string in VB.net?(如何在 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 中将日期转换为格式化字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 VB.net 中将日期转换为格式化字符串?


基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01