将时间和日期与此格式 HH.MM mm/dd/yyyy 进行比较. [英] Comparing Time And Date with this format HH.MM mm/dd/yyyy.
本文介绍了将时间和日期与此格式 HH.MM mm/dd/yyyy 进行比较.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以像这样使用军用时间和日期的格式进行比较HH.MM mm/dd/yyyy
.例如:
Is it possible to compare using The format of military time and Date like this HH.MM mm/dd/yyyy
.
For Example:
08.25 06/10/2014 > 23.18 06/09/2014
结果为真,因为第 10 天大于第 09 天
Result is True because the day 10 is greater than day 09
23.25 06/10/2014 > 23.30 06/10/2014
结果为假,因为 30 分钟大于 25 分钟
Result is false because the mins 30 is greater than mins 25
24.25 06/10/2014 > 1.30 06/10/2014
结果为真,因为 24 小时大于 1 小时
Result is true because the hrs 24 is greater than hrs 1
优先级是年份 ->月 ->日 ->小时 ->分钟.
The Priority is Year -> Month -> Day -> Hours -> mins.
推荐答案
似乎允许您使用非标准时间,例如 24.25
.然后你可以使用以下策略 - 提取日期,添加时间,比较.
Seems like you are allowed to have non-standard time like 24.25
.
Then you can use the following strategy - extract date, add time, compare.
Public Shared Function ToDateTime(ByVal value As String) As DateTime
Dim m As Match = Regex.Match(value, "^(?<hours>\d{1,2})\.(?<minutes>\d{2}) (?<date>\d{2}/\d{2}/\d{4})$")
If Not m.Success Then
Throw New ArgumentException("value")
End If
Dim dateOnly As DateTime = DateTime.ParseExact(m.Groups.Item("date").Value, "dd\/MM\/yyyy", CultureInfo.InvariantCulture)
Dim hours As Integer = Integer.Parse(m.Groups.Item("hours").Value)
Dim minutes As Integer = Integer.Parse(m.Groups.Item("minutes").Value)
Return dateOnly.AddHours(hours).AddMinutes(minutes)
End Function
用法:
Console.WriteLine(ToDateTime("08.25 06/10/2014") > ToDateTime("23.18 06/09/2014"))
Console.WriteLine(ToDateTime("23.25 06/10/2014") > ToDateTime("23.30 06/10/2014"))
Console.WriteLine(ToDateTime("24.25 06/10/2014") > ToDateTime("1.30 06/10/2014"))
这篇关于将时间和日期与此格式 HH.MM mm/dd/yyyy 进行比较.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文