简体   繁体   English

从数据行中提取时间戳

[英]Extract timestamp from row of data

I have an input csv file like: 我有一个输入csv文件,如:

0,Mike,2015-12-04 21:56:32 0,迈克,2015-12-04 21:56:32
1,Raj,2015-12-04 11:53:29 1,Raj,2015-12-04 11:53:29

I want to extract the timestamp from the file. 我想从文件中提取时间戳。 What is the easiest way to do it in Java. 在Java中最简单的方法是什么?

You can do it as follows: 你可以这样做:

while(reader.hasNext()) {
    String csvString = reader.nextLine();
    String[] splits = csvString.split(",");
    System.out.println("Record: " + splits[0] + " Timestamp: " + splits[2]);
}

Output: 输出:

Record: 0 Timestamp: 2015-12-04 21:56:32
Record: 1 Timestamp: 2015-12-04 11:53:29

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

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