只获取时间并与时间进行比较 [英] Get only time and compare with a time

查看:66
本文介绍了只获取时间并与时间进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想获取时间为01:30的格式,并比较时间是否大于10:30.

我没有得到要求的格式的时间.我得到的时间是10:48:34.7553785.
请解决我的问题.

谢谢你
Mohd Wasif

Hi all,

I want to get time as 01:30 format and want to compare it that if time is greater than 10:30.

I am not getting time in requested format .I am getting as 10:48:34.7553785.
Please sort out my problem.

Thanking You
Mohd Wasif

推荐答案

您不应将时间转换为字符串来比较时间.相反,您应该始终比较DateTime值.它不仅不依赖于字符串表示,而且更快,更受支持.

—SA
You should not convert time to string to compare time. Instead, you should always compare DateTime values. Not only it does not depend on string representation, it''s faster and more supportable.

—SA


嗨 莫哈德(Mohad),

您可以使用以下方法获得时间:

Hi Mohad,

You can get time using following method:

DateTime dt = DateTime.Now;
string HrTime12 = dt.ToString("hh:mm");//The hour, using a 12-hour clock from 01 to 12.
string HrTime24 = dt.ToString("HH:mm");//The hour, using a 24-hour clock from 00 to 23.




如果您想了解有关日期和时间格式的更多信息,请参考以下内容:
自定义日期和时间格式字符串 [




If you would like to see more about Date and Time format, please refer following:
Custom Date and Time Format Strings[^]

Thanks,
Imdadhusen


这篇关于只获取时间并与时间进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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