我的工作是将浮点数据转换为日期格式的字符串数据。
例如200611是20/06/11,9610604是96/06/04
我写了代码,但它没有给出预期的结果
我在互联网上搜索了一下,但只找到了旧版本的代码
我的版本是3.1.0
以下是我的代码
xAxis.setValueFormatter(new ValueFormatter(){
public String getFormatterValue(int value) throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yy/MM/dd");
Date date = simpleDateFormat.parse(Integer.toString(value));
SimpleDateFormat newFormat = new SimpleDateFormat("yy/MM/dd");
String dateString = newFormat.format(date);
return dateString;
}
});
发布于 2020-06-11 12:43:28
看起来您需要先使用yyMMdd
格式(而不是yy/MM/dd
)进行解析,然后使用yy/MM/dd
进行格式化。
发布于 2020-07-07 09:06:11
这是我在我的项目中用来将Float
值格式化为String
类型的时间。您需要为XAxisValueFormatter创建一个单独的类,并在其中进行转换。
class XAxisValueFormatter: ValueFormatter() {
override fun getAxisLabel(value: Float, axis: AxisBase?): String {
var formatter = DateTimeFormatter.ofPattern("dd-yyyy-MM")
var formattedDate = value.format(formatter)
return formattedDate
}
}
https://stackoverflow.com/questions/62324611
复制相似问题