question

Upvotes
Accepted
21 0 1 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 512.0 KiB each and 1.0 MiB total.

@per.inge.larsen

Hi,

Thank you for your participation in the forum.

Are any of the replies below satisfactory in resolving your query?

If yes please click the 'Accept' text next to the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

@per.inge.larsen

Hi,

Thank you for your participation in the forum.

Are any of the replies below satisfactory in resolving your query?

If yes please click the 'Accept' text next to the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

Upvotes
Accepted
21 0 1 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 512.0 KiB each and 1.0 MiB total.

Upvotes
120 3 4 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 512.0 KiB each and 1.0 MiB total.

Upvotes
21 0 1 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 512.0 KiB each and 1.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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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