question

Upvotes
Accepted
21 0 0 2

RFA Java API - Convert CONTR_MNTH to java.util.Date ?

I am using the RFA Java API.
My program is getting snapshots by using MarketDataSubscriber, receiving MarketDataItemEvent.
I don't use dictionary.
Field 41 CONTR_MNTH (CONTRACT MONTH) is ALPHANUMERIC, length = 4.
I want to convert the value to format dd/mm/yyyy or java.util.Date.
In example -> APR8 should be 01.04.2018
Is there a utility (method) in the API which solve this easily ?

treprfarfa-apijavadate
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
21 0 0 2

I've made my own parser which solved my problem.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
120 3 3 7

I think the 'recommended' way now is to use Java 8 new date classes:

Ex:

LocalDate.parse("2015-02-20");

see https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
21 0 0 2

@paulofogaca
Thank you for your answer. The content of Field 41 can be Q121 (01/01/2021), APR8 (01.04.2018), Y20 (01/01/2020) etc. It's not a normal datepattern.
LocalDate localDate = LocalDate.parse("APR8");
java.time.format.DateTimeParseException: Text 'APR8' could not be parsed at index 0

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

As the field is a string and has TR (or coming from some Exchange) custom formatted value (not standard date format), if you need the value as a date for calculation purposes and dealing with all possible variants then you need to write a method.

Check here for arguments for parse method:

https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

Click below to post an Idea Post Idea