Java 數(shù)據(jù)轉(zhuǎn)換

處理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)在可能有兩種方式:

  1. 使用 try 的方法
  2. 新建一個(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();
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容