数字转换为时间? [英] Convert numbers to time?

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

问题描述

有一个漂亮的方式(陆军时间包括)转换成简单的数字,以一个时间格式(AM,PM格式)?我可以做繁琐的做法,但我只是想知道是否有另一种方式

0800 => 8:00

2317 =>下午十一时17

解决方案

  DateTime的DT = DateTime.ParseExact(0800,HHMM,CultureInfo.InvariantCulture);
    串TimeString以= dt.ToString(H:毫米TT);
 

请参阅文档的格式为codeS。

Is there a slick way to convert simple numbers (Army time included) to a time format (am, pm format)? I can do the tedious approach, but I was just wondering if there was another way

0800 => 8:00 am

2317 => 11:17 pm

解决方案

    DateTime dt = DateTime.ParseExact("0800", "HHmm", CultureInfo.InvariantCulture);
    string timestring = dt.ToString("h:mm tt");

See documentation for format codes.

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

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