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 中将日期转换为格式化字符串?
- 在 C# 中异步处理项目队列 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 使用 rss + c# 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01