jdk8t提出的localDateTime

本文介绍Java 1.8中新的日期时间API,包括LocalDateTime类的使用方法及如何格式化日期时间。通过实例展示了从获取当前日期时间到自定义格式输出的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在jdk1.6我们所使用的是Date   日期类通过SimpleDateFormat进行格式的转换,但是在1.8版本中,发现有人采用了

LocalDateTime来使用,可以获取当前日期 当前也分  当前月 到毫秒。二常用的日期类型 只精确到了秒。

所以我认为基本的使用还是需要掌握一下的。但是类型之间,初步写的一个小东西。

package cn.com.taiji.lighting;


import java.time.LocalDateTime;
import java.time.chrono.Chronology;
import java.time.format.DateTimeFormatter;


public class LocalDateT {


public static void main(String[] args) {
LocalDateTime localDate = LocalDateTime.now();// 代表的是当前的时间
System.out.println(localDate);// 打印内容2018-05-09T13:25:08.273
DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern("yyyy:MM:dd HH:MM:ss");
String format = ofPattern.format(localDate);
System.out.println(format);
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值