Help with DateTime.Dateparse

HengeDK

Member
Licensed User
Longtime User
Im keep getting:

java.text.ParseException: Unparseable date: "// 00:00:00" (at offset 0)

B4X:
Dim YearDay As String 
   Dim YearMonth As String
   Dim YearYear As String 
   YearDay = rdINI(File.DirRootExternal, "wifesize.ini", "SESSION 2", "yearday", "")
   YearMonth = rdINI(File.DirRootExternal, "wifesize.ini", "SESSION 2", "yearmonth", "")
   YearYear = rdINI(File.DirRootExternal, "wifesize.ini", "SESSION 2", "yearyear", "")
   DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss"
   Dim UTC_TS As Long 
   UTC_TS = DateTime.DateParse(YearMonth & "/" & YearDay & "/" & YearYear & " 00:00:00") - DateTime.DateParse("01/01/1970 00:00:00")
   Log("UTC_TS: "&UTC_TS)

please help
 

Mahares

Expert
Licensed User
Longtime User
Replace:
B4X:
DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss"

With:
B4X:
DateTime.DateFormat = "MM/dd/yyyy"
DateTime.TimeFormat= "HH:mm:ss"

Replace:
B4X:
UTC_TS = DateTime.DateParse(YearMonth & "/" & YearDay & "/" & YearYear & " 00:00:00") - DateTime.DateParse("01/01/1970 00:00:00")
With:
B4X:
UTC_TS = DateTime.DateParse(YearMonth & "/" & YearDay & "/" & YearYear & " " & DateTime.TimeParse("00:00:00")) _
      - DateTime.DateParse("01/01/1970" & " " & DateTime.TimeParse("00:00:00" ))
 
Upvote 0

HengeDK

Member
Licensed User
Longtime User
thanks for your help

now I get

java.text.ParseException: Unparseable date: "// 1344549600000" (at offset 0)
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Since I did not have your dates, I tested my code below before I sent it you my answers and it works. Here is what I tested:
B4X:
Dim YearMonth,YearDay,YearYear As String
      YearMonth="08" :YearDay="10" :YearYear="2012"
    Dim UTC_TS As Long 
      DateTime.DateFormat = "MM/dd/yyyy"
      DateTime.TimeFormat= "HH:mm:ss"
    UTC_TS = DateTime.DateParse(YearMonth & "/" & YearDay & "/" & YearYear & " " & DateTime.TimeParse("00:00:00")) _
      - DateTime.DateParse("01/01/1970" & " " & DateTime.TimeParse("00:00:00" ))
      Dim MyDays As Int
      MyDays=UTC_TS/DateTime.TicksPerDay
    Msgbox( "No of days: " & MyDays & CRLF & "UTCTS: " &  UTC_TS,"")
You can run my code and see if it works for you.
 
Upvote 0
Top