日期转化为字符串 java_java8、jdk8日期转化成字符串详解

java8、jdk8日期转化成字符串

新建日期工具类:DateUtils

8b6929219d215ee9ffad2890f8989ac5.png

新建方法:parseDate

19a51f7c68aa3ac99b340dcf720ad133.png

实现方法parseDate

public static String parseDate(LocalDate localDate,String pattern) {

DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);

return localDate.format(dateTimeFormatter);

}

758d8c031e406b19dd5c395f74f9b280.png

在main方法编写测试:

public static void main(String[] args) {

System.out.print(parseDate(LocalDate.now(),"yyyy-MM-dd"));

}

08bf03b93f10c1409c3c709c1b78e8d0.png

这个工具类代码如下:

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"));

}

}

75113f9245eb2c508021a69c5f489797.png

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

2a2e4adb00e73a2629990e0fe226b5ad.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值