简体   繁体   English

将带有日期和时间的多个文本文件输入到Java程序中,以便从另一个日期中减去一个日期

[英]Feeding multiple text files with dates and times into a java program to subtract one date from another

I have 5 text files that have computer clock in and clock out times for each employee. 我有5个文本文件,每个员工都有计算机的上班时间和下班时间。

The first column of each file has an identification number for each employee, and the remaining 10 columns have clock in and clock out times for the week (clock in times are in columns 2,4,6,8 and 10 and clock out times are in columns 3,5,7,9 and 11). 每个文件的第一列都有每个员工的标识号,其余10列具有一周的上班和下班时间(上班时间在第2、4、6、8和10列中,而上班时间是在第3、5、7、9和11栏中)。

The dates are in EEE MM/dd/yyyy hh:mm a format. 日期采用EEE MM/dd/yyyy hh:mm a格式。

I need to subtract each clock in column from each clock out column next to it to get the total hours worked for that particular day (for example, column 3 has the clock out time for 11/7 and column 2 has the clock in time for the same date...so column 2 must be subtracted from column 3). 我需要从旁边的每个时钟输出列中减去每个时钟输入列,以获取该特定日期的总工作时间(例如,第3列的时钟输出时间为11/7,第2列的时钟输入时间为相同的日期...因此必须从第3列中减去第2列)。

I need a java program that can be fed all these files, read the dates and subtract them, and write the results to a new file with the ID numbers. 我需要一个Java程序,可以喂入所有这些文件,读取日期并减去它们,然后将结果写入具有ID号的新文件中。

I thought of maybe somehow converting the text files into one CSV file, putting them into a two dimensional array, and then subtracting one array column from the other but I'm not sure if this would work (and I'm not sure how to do this). 我想到了可能以某种方式将文本文件转换为一个CSV文件,将它们放入二维数组,然后从另一个数组中减去一个数组列,但是我不确定这是否行得通(而且我不确定如何做这个)。

I probably would have to use an arraylist since the number of rows of clock-in/out times could vary. 我可能必须使用arraylist,因为时钟输入/输出时间的行数可能会有所不同。

I really wanted to avoid lumping all the data into a single text file and having to move array or arraylist references endlessly to the right to subtract the dates. 我真的想避免将所有数据集中到一个文本文件中,而不必将数组或arraylist引用不断地向右移动以减去日期。

Any help you can give me would be much appreciated. 您能给我的任何帮助将不胜感激。

Thank you. 谢谢。

如果文件是用制表符分隔的,则可以使用此处接受的答案中所述的方法将数据读入arraylists: 读取由制表符分隔的文件,并将单词放入ArrayList中

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

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