Java修改Excel时间格式

原时间格式:
Java修改Excel时间格式_第1张图片
修改后的时间格式:
Java修改Excel时间格式_第2张图片
代码如下:

package com.tyut.rcr;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class dt {

    public static void main(String[] args) throws IOException {
        dt transformer = new dt();
        dt.readFile();
    }

    public static void readFile() throws IOException {
            String inputPath = "C:\\Users\\REN\\Desktop\\2016.08.MD.csv";
            String outputPath = "C:\\Users\\REN\\Desktop\\2016.08.1.MD.csv";
            File file =  new File(inputPath);
            FileWriter fileWriter=new FileWriter(outputPath, true);
            if (file.isFile()&&file.exists()){
                InputStreamReader iread = new InputStreamReader(new FileInputStream(inputPath));
                BufferedReader bufReader= new BufferedReader(iread);
                String line = null;
                String[] a = {};
                String[] b={};
                String[] c={};
                while((line=bufReader.readLine())!=null){
                    a=line.split(",");
                    if((!a[0].contains("#"))&&(!a[0].contains("当地时间"))){
                    b=a[0].split(" ");
                        if(b[1].charAt(3)!='3'){
                            c=b[0].split("\\.");
                            String d = c[2]+"/"+c[1]+"/"+c[0];
                            String na = d+" "+b[1]+":00";
                            fileWriter.write(na+","+line+","+"\n");
                        }
                    }   
                }
                iread.close();
                fileWriter.close();
            }

    }

}

你可能感兴趣的:(Java)