简体   繁体   English

日期未以CSV格式书写

[英]Date is not written in desired format in CSV

I have an array list which looks like below: 我有一个数组列表,如下所示:

data = new ArrayList<String[]>();

data.add(new String[] {"Date","Day_Of_Week"});

data.add(new String[] {"2011-1-10","xyz"});

data.add(new String[] {"2011-1-11","xyz"});

data.add(new String[] {"2011-1-12","xyz"});

Then, I write the data from the above ArrayList to a CSV file using following code: 然后,使用以下代码将上述ArrayList中的数据写入CSV文件:

String csv = "D:\\Output.csv";
CSVWriter writer = new CSVWriter(new FileWriter(csv));

writer.writeAll(data);

writer.close();
csvReader.close();

If I open my Output.csv file, the format of the date is: 如果打开Output.csv文件,则日期格式为:

1/10/2011

1/11/2011

1/12/2011

Can anybody help why this is happening? 有人可以帮忙为什么会这样吗? Does CSV file automatically change the format of the date when writing it int the file? 将CSV文件写入文件时,是否会自动更改日期格式?

Try to open file in another program. 尝试在另一个程序中打开文件。 For example notepad. 例如记事本。 Excel can show you reformat view. Excel可以向您显示重新格式化视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM