转换日期时间到指定的格式 [英] Convert DateTime to a specified Format

查看:260
本文介绍了转换日期时间到指定的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此日期格式 YY / MM / DD HH:MM:SS 例如: 21年12月2日10时56分○九秒。问题是,当我尝试使用这种code将其转换为不同的格式为:

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")

它显示十二月12,2021 10点56分○九秒

我怎样才能正确地它的格式为:二月21 2012 10点56分○九秒?当我检查余额查询我来回基于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")

这篇关于转换日期时间到指定的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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