【问题标题】:For loop not looping through all dataFor循环没有遍历所有数据
【发布时间】:2015-05-06 02:25:18
【问题描述】:

For Loop 没有在我的代码中循环遍历我的所有数据。我已经仔细阅读了它,仍然找不到任何错误。

希望这不是什么愚蠢的错误。

这是我的for loop 代码的 sn-p:

String convertedDuration= "";
String timeConverted = convertedDuration;

for (int i = 0; i < submissionTime.length; i ++)
    {
        String strDate = submissionTime[i];
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        Date getDate = sdf.parse(strDate);
        getDate.getTime();
        convertedDuration = timeConverted + (getDate.getTime());
    }

    System.out.println("convertedDuration : "+ convertedDuration);

提前感谢您的帮助:)

【问题讨论】:

    标签: java for-loop


    【解决方案1】:

    在循环内打印而不是在循环外打印。您只打印最后一个。将打印行移动到循环。

    for (int i = 0; i < submissionTime.length; i ++)
            {
                String strDate = submissionTime[i];
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
                Date getDate = sdf.parse(strDate);
                getDate.getTime();
                convertedDuration = timeConverted + (getDate.getTime());
                System.out.println("convertedDuration : "+ convertedDuration);
    }
    

    【讨论】:

    • 数据仍然不会循环。我放置打印行以检查它是否打印出我的每一行数据。它只打印已转换的第一行数据。
    • 然后检查您的submissionTime 。可能它只有一个值
    猜你喜欢
    • 2017-02-03
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    • 2017-03-09
    • 2017-05-14
    • 2015-12-29
    • 1970-01-01
    相关资源
    最近更新 更多