Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

java time

作者:旭旭移日   发布日期:2026-03-08   浏览:97

// Java Time API 示例代码

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class JavaTimeExample {
    public static void main(String[] args) {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        System.out.println("当前日期: " + currentDate);

        // 获取当前时间
        LocalTime currentTime = LocalTime.now();
        System.out.println("当前时间: " + currentTime);

        // 获取当前日期和时间
        LocalDateTime currentDateTime = LocalDateTime.now();
        System.out.println("当前日期和时间: " + currentDateTime);

        // 格式化日期时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDateTime = currentDateTime.format(formatter);
        System.out.println("格式化后的日期时间: " + formattedDateTime);

        // 解析字符串为日期时间
        LocalDateTime parsedDateTime = LocalDateTime.parse("2023-10-05T14:30:00");
        System.out.println("解析后的日期时间: " + parsedDateTime);
    }
}

说明:

  • LocalDate 用于表示不带时间的日期。
  • LocalTime 用于表示不带日期的时间。
  • LocalDateTime 用于表示带日期和时间的对象。
  • DateTimeFormatter 用于格式化和解析日期时间字符串。

上一篇:java格式化日期

下一篇:java long 转 int

大家都在看

java url decode

java判断是windows还是linux

java连接数据库的代码

java date类型比较大小

java djl

ubuntu 卸载java

es java api

java list 查找

java 解压rar

java读取excel中的图片

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站