用于GregorianCalendar数组列表的Java怪异系统输出

我目前试图从雅虎财经API收到的数据保存到不同的数组列表,但我有点麻烦

package Stocks;

   import java.text.*;
   import java.util.*;
   import java.net.URL;
   import java.net.URLConnection;
   import java.util.Calendar;
   import java.util.Collection;
   import java.util.Date;
   import java.util.GregorianCalendar;
   import java.util.Scanner;
   import java.util.Arrays;


public class StockDownload {

public static final int DATE = 0;
public static final int OPEN = 1;
public static final int HIGH = 2;
public static final int LOW = 3;
public static final int CLOSE = 4;
public static final int VOLUME = 5;
public static final int ADJUSTED = 6;

private ArrayList<GregorianCalendar>dates;
private ArrayList<Double>opens;
private ArrayList<Double>highs;
private ArrayList<Double>lows;
private ArrayList<Double>closes;
private ArrayList<Integer>volumes;
private ArrayList<Double>adjcloses;


public StockDownload(String symbol, 
        GregorianCalendar start, GregorianCalendar end){
dates = new ArrayList<GregorianCalendar>();
opens = new ArrayList<Double>();
highs = new ArrayList<Double>();
lows = new ArrayList<Double>();
closes = new ArrayList<Double>();
volumes = new ArrayList<Integer>();
adjcloses = new ArrayList<Double>();

String url = "http://ichart.yahoo.com/table.csv?s=" + symbol 
        + "&a=" + start.get(Calendar.MONTH)
        + "&b=" + start.get(Calendar.DAY_OF_MONTH)
        + "&c=" + start.get(Calendar.YEAR)
        + "&d=" + end.get(Calendar.MONTH)
        + "&e=" + end.get(Calendar.DAY_OF_MONTH)
        + "&f=" + end.get(Calendar.YEAR)
        + "&g=d" + "&ignore=.csv";

try{
    URL yahoofin = new URL(url);
    URLConnection data = yahoofin.openConnection();
    Scanner input = new Scanner(data.getInputStream());
    if(input.hasNext())
        input.nextLine();

    while(input.hasNextLine()){
        String line = input.nextLine();

        String info[] = line.split(",");    
        dates.add(getDates(info[0]));
    }
    for(int i = 0; i < dates.size(); i++){
    System.out.println(dates.get(i));

    }

}catch(Exception e){
    System.err.println(e);
}

}   
public GregorianCalendar getDates(String date){

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date rawdate = null;
    try {
        rawdate = df.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
    cal.setTime(rawdate);

    GregorianCalendar cleandate = cal;


    return cleandate;
}
}

输出im得到看起来像这样:java.util.GregorianCalendar [time = 1344229200000,areFieldsSet = true,areAllFieldsSet = true,lenient = true,zone = sun.util.calendar.ZoneInfo [id =“America / Chicago”,offset = -21600000,dstSavings = 3600000,useDaylight =真,过渡= 235,lastRule = java.util.SimpleTimeZone中[ID =美国/芝加哥,偏移= -21600000,dstSavings = 3600000,useDaylight =真,startYear = 0,STARTMODE = 3, startMonth = 2,朝九特派= 8,startDayOfWeek = 1,开始时间= 7200000,startTimeMode = 0,endMode = 3,endMonth = 10,endday指定= 1,一个endDayOfWeek = 1,结束时间= 7200000,endTimeMode = 0]],Firstdayofweek可= 1, minimalDaysInFirstWeek = 1,ERA = 1,YEAR = 2012,MONTH = 7,WEEK_OF_YEAR = 32,WEEK_OF_MONTH = 2,DAY_OF_MONTH = 6,DAY_OF_YEAR = 219,DAY_OF_WEEK = 2,DAY_OF_WEEK_IN_MONTH = 1,AM_PM = 0,HOUR = 0,HOUR_OF_DAY = 0,MINUTE = 0,SECOND = 0,微差= 0,ZONE_OFFSET = -21600000,DST_OFFSET = 3600000]

我认为这在技术上是正确的,只是比我需要更多的信息。

我测试了只是打印出存储在info []索引中的内容,我只是无法将数据推送到数组列表中。 任何援助或参考一些很好的阅读材料将不胜感激! 谢谢

PS发起这个类没有显示,但它所做的只是将必要的变量传递给StockDownload方法


然后,您想要使用相同的SimpleDateFormat进行打印,

System.out.println(dates.get(i)); //<-- change this

到类似的东西

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(df.format(dates.get(i).getTime()));
链接地址: http://www.djcxy.com/p/6253.html

上一篇: Java Weird System output for GregorianCalendar arraylist

下一篇: Get months between two dates ignoring the days