转换和比较时间 [英] Convert and compare times

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

问题描述

我有以下作为例子:



2016年8月1日@ 14:16作为文本框中的文本字符串。它没有格式化为日期时间字段,而只是格式化为文本字符串。这是因为用户将数据输入PDF(如上所示)并作为文本字符串导入...



我正在尝试的第一件事要做的是剥离日期,只有时间(14:16)并将调用result1。我相信我已经征服了(见下面的代码)。



然后我想取结果(14:16)并将其与实际格式化的日期时间字段进行比较仅包含没有日期的时间,14:00作为示例,并将调用result3。我希望看看result3是否更大(或之后)result1。



我的主要问题是正确获取仅时间字段(result3)以显示只是时间。通过debug运行时返回以下内容:

I have the following as an example:

01 Aug 2016 @ 14:16 as a text string in a text box. It is not formatted as a datetime field but simply as a text string. This is because of the way the users enter data into a PDF (as shown above) and that is imported as a text string...

1st thing I am trying to do is strip off the date and only have the time (14:16) and will call that "result1". I believe I have conquered that (see code below).

Then I want to take that result (14:16) and compare it to an actual formatted datetime field which contains only a time with no date, 14:00 as an example, and will call that "result3". I am looking to see if "result3" is greater (or after) "result1".

My major issue is properly getting the time only field (result3) to show just the time. It is returning the following when running via debug:

System.Windows.Forms.TextBox, Text: 14:00

我需要它才返回14: 00没有System.Windows.Forms.TextBox,文字:。



两个结果中的一个格式不正确,我怀疑,但不知道哪个。我应该在提取我需要的部分之后将result1转换为日期时间字符串,还是应该将result3转换为文本字符串?我的想法是两个都应该是datetime,因为我正在寻找result3是否在result1之后。



我确定这是格式化问题,但不确定如何正确读取日期时间框(result3)和/或将文本字段(result1)转换为比较日期时间(仅限时间)结果。



男人,我希望有道理......



最后一次请求:我是否正确地进行了CASE比较?



我尝试了什么:



and I need it to return only "14:00" without the "System.Windows.Forms.TextBox, Text:".

One of the two results is formatted incorrectly, I suspect, but not sure which. Should I convert result1 to a datetime string after extracting the portion I need or should I convert result3 to a text string? My thinking is both should be datetime since I am looking to see if result3 is after result1.

I'm certain this is a formatting issue but unsure how to get the datetime box (result3) to read properly and/or converting a text field (result1) to a datetime (time only) result for comparison.

Man, I hope that makes sense...

Last Request: Am I doing the CASE comparison properly?

What I have tried:

Private Sub tb01Time_TextChanged(sender As Object, e As EventArgs) Handles tb01Time.TextChanged
        Dim result1 As String = tb01Time.ToString
        Dim result2 As String = LoadRight(result1, 5)

        Dim result3 As String = tbShipArriveTime.ToString

        Dim late As String

        If result3 > result2 Then
            late = "True"
        Else
            late = "False"
        End If

        Select Case tbShipArriveTime.ToString
            Case = "True" : tb01Time.BackColor = Color.Red
                tb01Time.ForeColor = Color.White
            Case Else : tb01Time.BackColor = Color.White
                tb01Time.ForeColor = Color.Black
        End Select

    End Sub

推荐答案

解决了我自己的问题....



我在我的情况下使用了错误的变量 - 需要放入迟到是我的变量而不是tbShipArriveTime。
Resolved my own problem....

I was using the wrong variable in my case - needed to put in late as my variable instead of tbShipArriveTime.


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

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