gpt4 book ai didi

java - java中如何将字符串转换为RegularTimePeriod?

转载 作者:行者123 更新时间:2023-12-02 00:55:59 25 4
gpt4 key购买 nike

我正在使用 Jfreechart。我有这样的代码:

TimeSeries t1 = new TimeSeries("EUR/GBP");
t1.add(new Day(4, MonthConstants.JANUARY, 2001), new Double(1.5807));

但是我从 SQL 查询中得到了 String。 TimeSeries 仅接受 RegularTimePeriodTimeSeriesDataItem

请告诉我如何将 String 转换为 RegularTimePeriod

提前致谢。

最佳答案

首先,您可以通过使用 SimpleDateFormat 解析 mysql 日期字符串来获取 Date 对象,然后使用带有 Date 参数的构造函数创建 RegularTimePeriod。

基本上(假设 mysqlDateStr 是来自 mysql 查询的字符串):

SimpleDateFormat standardDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// (Define your formatter only once, then reuse)

Date myDate = standardDateFormat.parse(mysqlDateStr);
// (you may want to catch a ParseException)

t1.add(new Day(myDate), new Double(1.5807));

关于java - java中如何将字符串转换为RegularTimePeriod?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/421020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com