Android Question help with datetime

apty

Active Member
Licensed User
Longtime User
I have the following code that picks time in 24 hour format
B4X:
  DateTime.TimeFormat="HH:mm"
  timenow=DateTime.Time(DateTime.Now)
  lbltime.Text=timenow

I would like to add 3 minutes to lbltime.Text. How can i do that? I know i can add the minutes to timenow, but I want to add them to lbltime (later after i have already set lbltime)
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Dim timenow As Long
DateTime.TimeFormat="HH:mm"
timenow=DateTime.Now
Log("TimeNow: "&DateTime.Time(timenow))
Dim per As Period
per.Initialize
per.Minutes = 3
Log("New Time: "&DateTime.Time(DateUtils.AddPeriod(timenow,per)))

Note that you need to check the library DateUtils
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
It gives me an error
invalid double: "20:33" when i try to capture the time in a textview so that i can put it in the lbltime label
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
B4X:
lbltime.Text=txtSettime.Text
    Dim servtime As String
    Dim per As Period
    per.Initialize
    per.Minutes = 2
    'Log("New Time: "&DateTime.Time(DateUtils.AddPeriod(lbltime.Text,per)))
   
    servtime=DateTime.Time(DateUtils.AddPeriod(lbltime.Text,per))
    lbltimetowritetoserver.Text=servtime

That is the code
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
AddPeriod expects a first parameter a datetime (a long)... You also DID NOT recognized my hint about parse...
you first need to convert the string to a datetime value... USE the forumsearch

DateTime.TimeFormat="HH:mm"
Dim timenow As Long
timenow = DateTime.TimeParse(EditText1.Text)
Log("TimeNow: "&DateTime.Time(timenow))
Dim per As Period
per.Initialize
per.Minutes = 3
Log("New Time: "&DateTime.Time(DateUtils.AddPeriod(timenow,per)))
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
You also DID NOT recognized my hint about parse...
you first need to convert the string to a datetime value... USE the forumsearch


Date and Time values are presented in Ticks, therefore the need to parse them from human values to machine readable ones
DateTime.TimeFormat="HH:mm"
Dim timenow As Long
timenow = DateTime.TimeParse(EditText1.Text)
Log("TimeNow: "&DateTime.Time(timenow))
Dim per As Period
per.Initialize
per.Minutes = 3
Log("New Time: "&DateTime.Time(DateUtils.AddPeriod(timenow,per))
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
i tried the following
B4X:
lbltime.Text=txtSettime.Text

    Dim servtime As Long
    Dim diskwtime As Long
    Dim per As Period
    'servtime=DateTime.TimeParse(lbltime.Text)
    diskwtime=DateTime.TimeParse(lbltime.Text)
    per.Initialize
    per.Minutes = 2
   
    diskwtime=lbltime.Text
    servtime=DateTime.Time(DateUtils.AddPeriod(diskwtime,per))
    lbltimetowritetoserver.Text=servtime
But i still get invalid double error
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
i tried the following
B4X:
lbltime.Text=txtSettime.Text

    Dim servtime As Long
    Dim diskwtime As Long
    Dim per As Period
    'servtime=DateTime.TimeParse(lbltime.Text)
    diskwtime=DateTime.TimeParse(lbltime.Text)
    per.Initialize
    per.Minutes = 2

    diskwtime=lbltime.Text
    servtime=DateTime.Time(DateUtils.AddPeriod(diskwtime,per))
    lbltimetowritetoserver.Text=servtime
But i still get invalid double error

Sure you get an error...

B4X:
 Dim servtime As Long
    Dim diskwtime As Long
    Dim per As Period
    'servtime=DateTime.TimeParse(lbltime.Text)
    diskwtime=DateTime.TimeParse(lbltime.Text) ' <--- Here you are doing it right
    per.Initialize
    per.Minutes = 2

    diskwtime=lbltime.Text ' <-- here you are doing the same error as before...BTW: This line is not needed
    servtime=DateTime.Time(DateUtils.AddPeriod(diskwtime,per))
    lbltimetowritetoserver.Text=servtime
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
I have commented the line
B4X:
diskwtime=lbltime.Text
out. But the error is still there
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You should do debugging. WHICH error yxou get exactly? Which code are you using?
Which line of code runs when the error occurs...

My code above works. I have tested.

Actually i´m not sure which line should bring this error...

You can upload your actual project and we can have a look. OR you give us more detailed informations...
 
Last edited:
Upvote 0
Top