简体   繁体   中英

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.

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).

The dates are in EEE MM/dd/yyyy hh:mm a format.

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).

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.

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).

I probably would have to use an arraylist since the number of rows of clock-in/out times could vary.

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.

Any help you can give me would be much appreciated.

Thank you.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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