java8、jdk8日期轉(zhuǎn)化成字符串詳解
更新時間:2019年04月14日 15:35:04 投稿:laozhang
在本篇文章中小編給大家整理了關(guān)于java8、jdk8日期轉(zhuǎn)化成字符串的相關(guān)知識點和代碼,需要的朋友們學習下。
java8、jdk8日期轉(zhuǎn)化成字符串
新建日期工具類:DateUtils

新建方法:parseDate

實現(xiàn)方法parseDate
public static String parseDate(LocalDate localDate,String pattern) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
return localDate.format(dateTimeFormatter);
}

在main方法編寫測試:
public static void main(String[] args) {
System.out.print(parseDate(LocalDate.now(),"yyyy-MM-dd"));
}

這個工具類代碼如下:
package com.gwolf;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class DateUtils {
public static String parseDate(LocalDate localDate,String pattern) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
return localDate.format(dateTimeFormatter);
}
public static void main(String[] args) {
System.out.print(parseDate(LocalDate.now(),"yyyy-MM-dd"));
}
}

測試工具方法,查看結(jié)果:

相關(guān)文章
Thread線程的基礎(chǔ)知識及常見疑惑點總結(jié)
在本篇內(nèi)容里小編給大家分享的是關(guān)于Thread線程的基礎(chǔ)知識及常見疑惑點,對此有學習需求的朋友們可以學習參考下。2019-05-05
springboot Actuator的指標監(jiān)控可視化功能詳解
SpringBoot Actuator是springboot為簡化我們對微服務項目的監(jiān)控功能抽取出來的模塊,使得我們每個微服務快速引用即可獲得生產(chǎn)界別的應用監(jiān)控、審計等功能。這篇文章主要介紹了springboot Actuator的指標監(jiān)控可視化,需要的朋友可以參考下2021-08-08
java實用型-高并發(fā)下RestTemplate的正確使用說明
這篇文章主要介紹了java實用型-高并發(fā)下RestTemplate的正確使用說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-10-10
關(guān)于Java Guava ImmutableMap不可變集合源碼分析
這篇文章主要介紹Java Guava不可變集合ImmutableMap的源碼分析的相關(guān)資料,需要的朋友可以參考下面具體的文章內(nèi)容2021-09-09
Kotlin基礎(chǔ)教程之控制流(順序,分支,循環(huán))
這篇文章主要介紹了Kotlin基礎(chǔ)教程之控制流的相關(guān)資料,需要的朋友可以參考下2017-05-05

