我正在尝试使用 java money-api 和 moneta 存储库进行简单的货币转换。
<dependency>
<groupId>javax.money</groupId>
<artifactId>money-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta</artifactId>
<version>1.4.2</version>
</dependency>
IMFHistoricRateProvider imf = new IMFHistoricRateProvider();
LocalDate now = LocalDate.now();
ExchangeRate exr = null;
long start = System.currentTimeMillis();
LocalDate date = LocalDate.parse("2021-05-25", DateTimeFormatter.ISO_LOCAL_DATE);
exr = imf.getExchangeRate(ConversionQueryBuilder.of().setBaseCurrency("EUR").setTermCurrency("USD").set(LocalDate.class, date).build());
System.out.println(exr.getFactor() + " ==" + (System.currentTimeMillis()-start));
这里 exr.getFactor() 方法给出了给定日期的汇率,但它在一个状态下挂了几个小时。
PF日志在其挂起。
May 27, 2021 4:59:26 PM org.javamoney.moneta.spi.loader.LoadDataLoaderService execute
INFO: Read data from: [https://www.imf.org/external/np/fin/data/rms_five.aspx?tsvflag=Y]
May 27, 2021 4:59:26 PM org.javamoney.moneta.convert.imf.IMFAbstractRateProvider newDataLoaded
INFO: Loaded IMFHistoricRateProvider exchange rates for days:50
May 27, 2021 4:59:26 PM org.javamoney.moneta.spi.loader.LoadDataLoaderService execute
INFO: New data successfully loaded from: [https://www.imf.org/external/np/fin/data/rms_five.aspx?tsvflag=Y]
它应该给出过去 X 本地日期从 EUR 到 USD 的汇率。
参考:https ://dzone.com/articles/looking-java-9-money-and (汇率)