Java經典例項:把字串解析為日期時間

FrankYou發表於2016-11-28

Java版本:1.8開始

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * Created by Frank
 */
public class DateParse {
    public static void main(String[] args) {
        String armisticeDate  = "1914-11-11";
        LocalDate alD = LocalDate.parse(armisticeDate);
        System.out.println("Date:" + alD);

        String armisticeDateTime = "1914-11-11T11:11";
        LocalDateTime aLDT = LocalDateTime.parse(armisticeDateTime);
        System.out.println("Date/Time:" + aLDT);
    }
}

執行輸出:

Date:1914-11-11
Date/Time:1914-11-11T11:11

 

相關文章