iOS Question Datetime Picker

David Hawkins

Active Member
Licensed User
Longtime User
Hi I am getting somer confusing results using the following:

I have 2 Datetime pickers I can select date and time on both which is what I want to do, however when using the following code

Datetime Picker:
        Dim FirstDateAndTime As String = DateTime.Date(DatePicker1.Ticks) & " " & DateTime.Time(DatePicker1.Ticks)
        Dim LastDateAndTime As String = DateTime.Date(DatePicker2.Ticks) & " " & DateTime.Time(DatePicker2.Ticks)

it provides the following output '09/07/2023 13:30' but the datetime picker is showing '9 Jul 2023 06:00'

I am confused, I'm obviously doing something wrong but what, some assistance please?

Regards

David
 

David Hawkins

Active Member
Licensed User
Longtime User
Hi Erel, I think I might have found out what the problem is, I set the timezone to 0 as I am in the UK and Greenwich Meantime is 0 but that gives me the wrong time. I have now checked it with the timezone set to 1 and it gives me the correct time. I wonder if that is an underlying problem going forward. I'm going to do some more tests and will report back shortly. Thank you for your reply.
Regards
David
 
Upvote 0

David Hawkins

Active Member
Licensed User
Longtime User
Hi Erel, I had to change my code to the following for everything to work as I wanted

B4X:
    DateTime.DateFormat = "dd/MM/yyyy"
    DateTime.TimeFormat = "HH:mm"
    DateTime.SetTimeZone(1)
    
    Dim FTAndD As String = DateTime.Date(DTP1.Ticks) & " " & DateTime.Time(DTP1.Ticks)   'this gives me the correct date and time
    Dim LTAndD As String = DateTime.Date(DTP2.Ticks) & " " & DateTime.Time(DTP2.Ticks)

    DateTime.SetTimeZone(0)
    
    Dim t As Long = DTP2.Ticks - DTP1.Ticks
    
    Dim dt As String = DateTime.GetHour(t) & ":" & DateTime.GetMinute(t) ' this gives me the correct hours and minutes difference

    Label1.Text = dt

    xui.MsgboxAsync(FTAndD & " - " & LTAndD, "B4X")

It now appears to be working as expected.

Your intervention made me think more about exactly what I wanted

Many Regards
David
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…