B4J Question Date Convert

TomDuncan

Active Member
Licensed User
Longtime User
Hi All,
I have a date in the format..
Delivery-date: Wed, 07 Oct 2015 19:29:59 -0500
How can I convert this.
I have tried this..
B4X:
        DateTime.DateFormat=  "ddd, dd MMM yyyy"
        DateTime.TimeFormat="HH:mm:ss a"
        Dim q As String = m.delivery
        Dim tickC As Long = DateTime.DateTimeParse(q.SubString2(0,15),q.SubString(16))
Log(DateTime.Date(tickC))

But get this error.
java.text.ParseException: Unparseable date: " Wed, 07 Oct 20"

Any thoughts.
Tom
 

Roycefer

Well-Known Member
Licensed User
Longtime User
You don't need the "Wed, " part. It's not adding any information that you need. Lop that off: q.SubString2(5,15) instead of q.SubString2(0,15). And use "dd MMM yyyy" as your DateFormat.

Also, the "a" in your TimeFormat will cause more errors. It means "am/pm marker". See: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html Replace it with a "Z" or "X" (make sure it's capitalized). This means timezone.
 
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Have done some tests and looked into the Date formats.
With this code..
B4X:
        DateTime.DateFormat=  "dd MMM yyyy"
        DateTime.TimeFormat="HH:mm:ss Z"
        Dim q As String = m.delivery
        Log("." & q.SubString2(5,17) & "." & q.SubString(18) & ".")
        Dim tickC As Long = DateTime.DateTimeParse(q.SubString2(5,17),q.SubString(18))
        DateTime.DateFormat=  "yyyy-mm-dd HH:mm:ss"
        Log(m.delivery & " = " & DateTime.Date(tickC))
I get this result.
B4X:
btnGetMessages
Checking mails
Found messages: 4
. 07 Oct 2015.19:08:27 -0500.
Wed, 07 Oct 2015 19:08:27 -0500 = 2015-08-08 00:08:27
. 07 Oct 2015.19:29:59 -0500.
Wed, 07 Oct 2015 19:29:59 -0500 = 2015-29-08 00:29:59
. 07 Oct 2015.19:26:21 -0500.
Wed, 07 Oct 2015 19:26:21 -0500 = 2015-26-08 00:26:21
. 07 Oct 2015.20:05:28 -0500.
Wed, 07 Oct 2015 20:05:28 -0500 = 2015-05-08 01:05:28
The splitting of the date string seems to be ok, but..
The Dates are wrong and the month comes out as the minute.
I am sure the Capitals are correct. (well I hope so)

Tom
 
Upvote 0
Top