處理NSE數(shù)據(jù)的時(shí)候,輸入一個(gè)日期,確定它到底是星期幾。
String timeStamp = nextLine[1].substring(0,10);
SimpleDateFormat dateStringFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = dateStringFormat.parse(timeStamp);
SimpleDateFormat date2DayFormat = new SimpleDateFormat("u");
String weekDay = date2DayFormat.format(date);
比如輸入如果是“2016-06-30”,則輸出為“4”
將 String 中的數(shù)字轉(zhuǎn)化為可以進(jìn)行計(jì)算的數(shù)字。
hourMin = Integer.parseInt(nextLine[1].substring(11,13))*3600 +
Integer.parseInt(nextLine[1].substring(14,16))*60 +
Integer.parseInt(nextLine[1].substring(17,19));
nextLine[1] 中11,12位代表小時(shí);14,15位代表分鐘;17,18位則表示秒。
調(diào)用一個(gè)類(lèi)中的方法,現(xiàn)在可能有兩種方式:
- 使用 try 的方法
- 新建一個(gè)類(lèi),通過(guò)“類(lèi).方法名”的方式
原程序結(jié)構(gòu):
import com.opencsv.CSVReader;
public class CSVParser{
public static void method1() throws IOException, ParseEception
{}
public static void method2() throws IOException, ParseException
{}
}
public static void main(String [] args) throws IOEception, ParseException
{
/*在這兒調(diào)用方法1和2*/
}
*使用 try 方法調(diào)用 method1():
try {
method1();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
*使用“類(lèi).方法名”的方式調(diào)用method2():
CsvParser hour_Hour_file;
hour_Hour_file = new CsvParser();
hour_Hour_file.method2();