java8、jdk8日期转化成字符串详解
时间:2020-10-09 22:41:31|栏目:JAVA代码|点击: 次
java8、jdk8日期转化成字符串
新建日期工具类:DateUtils

新建方法:parseDate

实现方法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"));
}
}

测试工具方法,查看结果:



阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机




