DateTime 12hrs至24hrs格式 [英] DateTime 12hrs to 24hrs format

查看:152
本文介绍了DateTime 12hrs至24hrs格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似"28/09/2012 04:00 PM"的字符串,我想将其转换为24小时
(即dd/MM/yyyy HH:mm)格式..请有人帮我解决这个问题


预先谢谢您.

i have a string like "28/09/2012 04:00 PM" i want to convert it into 24hrs
(i.e dd/MM/yyyy HH:mm) format..please anybody help me out in this


Thank You in advance

推荐答案

使用ParseExact将其转换为DateTime,然后将其输出为所需的任何格式.
Convert it to a DateTime, using ParseExact, then output it as whatever format you wish.
string s = "28/09/2012 04:00 PM";
DateTime dt = DateTime.ParseExact(s, "dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture);
s = dt.ToString("dd/MM/yyyy HH:mm");




试试这个代码:
Hi,

try this code:
DateTime dt = Convert.ToDateTime("28/09/2012 04:00 PM");
MessageBox.Show(dt.ToString("dd/MM/yyyy HH:mm"));


请参阅此处以获取可用模式的参考:
http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8- F859AA20581F.htm [ ^ ]


See here for a reference of the available patterns:
http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm[^]


您必须使用"H"或"HH"

h或hh将以12小时格式给出时间
其中
H或HH将以24小时格式给出时间.

You have to use "H" or "HH"

h or hh will give time in 12 hour format
where
H or HH will give time in 24 hr format.

string date=DateTime.Today.ToString("dd/MM/yyyy HH:mm");


这篇关于DateTime 12hrs至24hrs格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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