iOS Question Problem with DateTime

WebQuest

Active Member
Licensed User
Hi guys I have a problem with DateTime I am trying to store a date in a variable for a long time and then use it but I get an error.

java.lang.NumberFormatException: For input string: "11:30"

I am using the code of my B4a app which works correctly but on B4i it does not work....

CODE:
dim VarTime as long

DateTime.TimeFormat="HH:mm"

VarTime=DateTime.Time("11:30")

log(VarTime)
 

William Lancee

Well-Known Member
Licensed User
Longtime User
It also doesn't work in B4J. You need TimeParse.
B4X:
    DateTime.TimeFormat = "HH:mm"
    Dim dt As Long = DateTime.TimeParse("11:30")
    Log(DateTime.Time(dt))
 
Upvote 0

WebQuest

Active Member
Licensed User
Sorry if I expressed myself wrong! the b4a code includes the DateTime.TimeParse method which on B4i is not present and I thought its equivalent was DateTime.Time .... Excuse my ignorance and little experience on B4i but I believed the methods were the same for B4j, B4a, B4i.

Does anyone know in B4i what is the equivalent method for (DateTime.TimeParse)?
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
You can use DateTime.DateTimeParse
Android's DateTime.TimeParse ("11:30") is equal DateTime.DateTimeParse (DateTime.Date (DateTime.Now), "11:30")
 
Last edited:
Upvote 0

WebQuest

Active Member
Licensed User
I get this error. Can you give an example with DateTimeParse?

Error parsing: 1617579084124
Stack Trace: (
CoreFoundation F3021642-E3C0-33F8-9911-DD303A6056D0 + 1157612
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation F3021642-E3C0-33F8-9911-DD303A6056D0 + 120016
TestApp -[B4IDateTime DateParse:] + 160
TestApp -[B4IDateTime DateTimeParse::] + 192
CoreFoundation F3021642-E3C0-33F8-9911-DD303A6056D0 + 1175856
CoreFoundation F3021642-E3C0-33F8-9911-DD303A6056D0 + 8656
TestApp +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
TestApp -[B4IShell runMethod:] + 448
TestApp -[B4IShell raiseEventImpl:method:args::] + 1648
TestApp -[B4IShellBI raiseEvent:event:params:] + 1580
TestApp __33-[B4I raiseUIEvent:event:params:]_block_invoke + 60
libdispatch.dylib AF27E74C-BE4A-3364-BB27-AED9916CE02D + 393880
libdispatch.dylib AF27E74C-BE4A-3364-BB27-AED9916CE02D + 397952
libdispatch.dylib AF27E74C-BE4A-3364-BB27-AED9916CE02D + 65628
CoreFoundation F3021642-E3C0-33F8-9911-DD303A6056D0 + 632288
CoreFoundation F3021642-E3C0-33F8-9911-DD303A6056D0 + 608904
CoreFoundation CFRunLoopRunSpecific + 572
GraphicsServices GSEventRunModal + 160
UIKitCore CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 11723508
UIKitCore UIApplicationMain + 164
TestApp main + 128
libdyld.dylib 0B475C78-3C12-3121-B7F8-2B95B83DAF44 + 5480
)
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
B4X:
    Dim VarTime As Long
    DateTime.TimeFormat = "HH:mm"
    VarTime = DateTime.DateTimeParse (DateTime.Date (DateTime.Now), "11:30")
    Log (VarTime) ' Output (on my PC) is 1617561000000
 
Upvote 0

WebQuest

Active Member
Licensed User
this works fine thanks. One last thing for this thrend. How can I make a comparison in B4a I have used:

B4X:
    If VarTimeNow<VarTime Then     
      'code'
    end if
 
Upvote 0

WebQuest

Active Member
Licensed User
I have a problem with DateTime (DateTime.now) always returns 01:00 instead of the current time! how do i solve?

i am using this code:


B4X:
TimeNow = DateTime.Time(DateTime.Now)
 
Last edited:
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
What works ?
DateTime.Now returns the current time represented as the number of milliseconds since 1/1/1970 00:00 UTC.
Meanwhile you told about human representation (01:00).
 
Upvote 0

WebQuest

Active Member
Licensed User
Sorry I didn't express myself well. At the moment I have solved all the problems mentioned above.
To convert a set date this code was fine:
B4X:
    Dim VarTime As Long
    DateTime.TimeFormat = "HH:mm"
    VarTime=DateTime.DateTimeParse(DateTime.Date (DateTime.Now),"17:00")
    Log (DateTime.Time(VarTime))

To get DateTime.Now case 'A' works:
B4X:
'Case A
VarTimeNow = DateTime.Now

'Case B this get '01:00'
VarTimeNow = DateTime.Time(dateTime.Now)
 
Upvote 0
Top