本文介绍了将 DateTime 转换为指定格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个日期格式 yy/MM/dd HH:mm:ss
例如:12/02/21 10:56:09
.问题是,当我尝试使用以下代码将其转换为不同的格式时:
I have this date format yy/MM/dd HH:mm:ss
ex: 12/02/21 10:56:09
. The problem is, when i try to convert it to different format using this code:
CDate("12/02/21 10:56:09").ToString("MMM. dd, yyyy HH:mm:ss")
它显示 Dec.2021 年 12 月 12 日 10:56:09
.
我如何正确地将其格式化为:Feb.2012 年 10 月 21 日 10:56:09
?当我检查基于 SMS 的应用程序的余额查询时,将返回此格式.
How can i correctly format it to: Feb. 21, 2012 10:56:09
? This format is returned when i check balance inquiry fro my SMS based application.
推荐答案
使用 DateTime.ParseExact
,例如:
Use DateTime.ParseExact
, e.g.:
DateTime.ParseExact("12/02/21 10:56:09", "yy/MM/dd HH:mm:ss",
CultureInfo.InvariantCulture
).ToString("MMM. dd, yyyy HH:mm:ss")
这篇关于将 DateTime 转换为指定格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!