首页 > 解决方案 > 在java中获取ResultTable []的第一个元素

问题描述

这些代码:

String genType = FileConstants.CHANGE_CYCLE;
ResultTable[] genericCode = RTManager.getRTCsmGenericCodesDecodeList(genType);
String genCode = Arrays.toString(genericCode);

返回这些值:

genCode = [[code=22:00:00]

[dCode=Cut-off time for change bill_cycle if existing cycle_close_date=activity_date]]

问题:我如何获取 only'22:00:00'并将其转换为Time datatype

标签: javaarraystime

解决方案


如果 ResultTable 数组中的项目有一个 toString() 并且它产生字符串,那么你可以像这样得到它。

genericCode[0].toString().split("=")[1]


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateExample {

    public static void main(String[] args) {

        String time = "22:00:00";
        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
        Date date;
        try {
            date = sdf.parse(time);
            System.out.println("Time: " + sdf.format(date));
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }
}

推荐阅读