Java经典实例:把字符串解析为日期时间

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

 

posted @ 2016-11-28 18:47  FrankYou  阅读(3791)  评论(0编辑  收藏  举报