将时间转换为hh:mm tt [英] Convert time to hh:mm tt

查看:82
本文介绍了将时间转换为hh:mm tt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在标签文本081344中获得此值..
我必须将上午08:13:44转换为

i am getting this value in label text 081344..
i have to convert 08:13:44 am

推荐答案

将其转换为DateTime:
Convert it to a DateTime:
string inp = "081344";
DateTime dt = DateTime.ParseExact(inp, "hhmmss", CultureInfo.InvariantCulture);


然后在最后一个可能的时刻将其转换回字符串:


Then convert it back to a string at the last possible moment:

string outp = dt.ToString("hh:mm:ss tt");


这里有DateTime格式字符串的列表:格式化DateTime显示-格式字符串说明 [


There is a list of the DateTime format strings here: Formatting a DateTime for display - format string description[^]


什么是
报价:

081344


无论如何,您应该先在这里尝试
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]


Any way, you should be trying here first
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]


您好,Nikhil

首先,您必须将值转换为datatime格式.
字符串yourValue ="081344";
DateTime mDT = DateTime.ParseExact(yourValue,"hhmmss",CultureInfo.InvariantCulture);

然后,您必须使用string.Format方法:
字符串最终值= string.Format("{0:T}",mDT);

希望这项工作
Hi Nikhil

First You have to convert your value into datatime format.
string yourValue="081344";
DateTime mDT =DateTime.ParseExact(yourValue,"hhmmss",CultureInfo.InvariantCulture);

Then you have to use string.Format method:
string Finalvalue = string.Format("{0:T}",mDT);

Hope This Work


这篇关于将时间转换为hh:mm tt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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