国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Java8日期時(shí)間類LocalDateTime格式化

這篇具有很好參考價(jià)值的文章主要介紹了Java8日期時(shí)間類LocalDateTime格式化。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

Java8日期時(shí)間類LocalDateTime格式化

LocalDateTime日期時(shí)間格式化

LocalDateTime localDateTime = LocalDateTime.now()
System.out.println(now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

localDateTime.format(`DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")

測(cè)試1

	public static void main(String...arguments)throws Exception{
		
		LocalDateTime now = LocalDateTime.now();		
		
		System.out.println(now);
		System.out.println(now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
		System.out.println(now.format(DateTimeFormatter.BASIC_ISO_DATE));
		System.out.println(now.format(DateTimeFormatter.ISO_DATE));
		System.out.println(now.format(DateTimeFormatter.ISO_DATE_TIME));
		System.out.println(now.format(DateTimeFormatter.ISO_TIME));
//		System.out.println(now.format(DateTimeFormatter.ISO_INSTANT));  //會(huì)報(bào)錯(cuò)
		System.out.println(now.format(DateTimeFormatter.ISO_LOCAL_DATE));
		System.out.println(now.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
		System.out.println(now.format(DateTimeFormatter.ISO_LOCAL_TIME));
//		System.out.println(now.format(DateTimeFormatter.ISO_OFFSET_DATE));   //會(huì)報(bào)錯(cuò)
//		System.out.println(now.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));     //會(huì)報(bào)錯(cuò)
//		System.out.println(now.format(DateTimeFormatter.ISO_OFFSET_TIME));    //會(huì)報(bào)錯(cuò)
		System.out.println(now.format(DateTimeFormatter.ISO_ORDINAL_DATE));
		System.out.println(now.format(DateTimeFormatter.ISO_WEEK_DATE));
//		System.out.println(now.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));    //會(huì)報(bào)錯(cuò)
//		System.out.println(now.format(DateTimeFormatter.RFC_1123_DATE_TIME));   //會(huì)報(bào)錯(cuò)
	}

測(cè)試2

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

public class TestLocalDateTime230612 {
	
	public static void main(String...arguments)throws Exception{
		
		LocalDateTime now = LocalDateTime.now();
		
		
		pln("原樣toString()" , now.toString());
		pln("DateTimeFormatter.ofPattern(\"yyyy-MM-dd HH:mm:ss\")" , now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
		pln("DateTimeFormatter.BASIC_ISO_DATE)" , now.format(DateTimeFormatter.BASIC_ISO_DATE));
		pln("DateTimeFormatter.ISO_DATE" , now.format(DateTimeFormatter.ISO_DATE));
		pln("DateTimeFormatter.ISO_DATE_TIME)" , now.format(DateTimeFormatter.ISO_DATE_TIME));
		pln("DateTimeFormatter.ISO_TIME)" , now.format(DateTimeFormatter.ISO_TIME));
//		pln("" , now.format(DateTimeFormatter.ISO_INSTANT));  //會(huì)報(bào)錯(cuò)
		pln("DateTimeFormatter.ISO_LOCAL_DATE)" , now.format(DateTimeFormatter.ISO_LOCAL_DATE));
		pln("DateTimeFormatter.ISO_LOCAL_DATE_TIME)" , now.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
		pln("DateTimeFormatter.ISO_LOCAL_TIME)" , now.format(DateTimeFormatter.ISO_LOCAL_TIME));
//		pln("" , now.format(DateTimeFormatter.ISO_OFFSET_DATE));   //會(huì)報(bào)錯(cuò)
//		pln("" , now.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));     //會(huì)報(bào)錯(cuò)
//		pln("" , now.format(DateTimeFormatter.ISO_OFFSET_TIME));    //會(huì)報(bào)錯(cuò)
		pln("DateTimeFormatter.ISO_ORDINAL_DATE)" , now.format(DateTimeFormatter.ISO_ORDINAL_DATE));
		pln("DateTimeFormatter.ISO_WEEK_DATE)" , now.format(DateTimeFormatter.ISO_WEEK_DATE));
//		pln("" , now.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));    //會(huì)報(bào)錯(cuò)
//		pln("" , now.format(DateTimeFormatter.RFC_1123_DATE_TIME));   //會(huì)報(bào)錯(cuò)
	}
	
	static void pln(String a, Object b) {
		while(a.length()<"DateTimeFormatter.ofPattern(\"yyyy-MM-dd HH:mm:ss\")".length())a+=" ";
		System.out.println  (a + "  的效果:  " + b);
	}	
}

測(cè)試2的結(jié)果文章來源地址http://www.zghlxwxcb.cn/news/detail-480612.html

原樣toString()                                       的效果:  2023-06-12T22:50:54.825257400
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")  的效果:  2023-06-12 22:50:54
DateTimeFormatter.BASIC_ISO_DATE)                   的效果:  20230612
DateTimeFormatter.ISO_DATE                          的效果:  2023-06-12
DateTimeFormatter.ISO_DATE_TIME)                    的效果:  2023-06-12T22:50:54.8252574
DateTimeFormatter.ISO_TIME)                         的效果:  22:50:54.8252574
DateTimeFormatter.ISO_LOCAL_DATE)                   的效果:  2023-06-12
DateTimeFormatter.ISO_LOCAL_DATE_TIME)              的效果:  2023-06-12T22:50:54.8252574
DateTimeFormatter.ISO_LOCAL_TIME)                   的效果:  22:50:54.8252574
DateTimeFormatter.ISO_ORDINAL_DATE)                 的效果:  2023-163
DateTimeFormatter.ISO_WEEK_DATE)                    的效果:  2023-W24-1

到了這里,關(guān)于Java8日期時(shí)間類LocalDateTime格式化的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【Java 基礎(chǔ)篇】Java日期和時(shí)間格式化與解析指南:SimpleDateFormat詳解

    【Java 基礎(chǔ)篇】Java日期和時(shí)間格式化與解析指南:SimpleDateFormat詳解

    日期和時(shí)間在軟件開發(fā)中經(jīng)常被用到,無論是用于記錄事件、計(jì)算時(shí)間間隔還是格式化日期以供用戶友好的展示。Java 提供了強(qiáng)大的日期和時(shí)間處理工具,其中 SimpleDateFormat 類是一個(gè)重要的工具,用于格式化日期和時(shí)間,同時(shí)也支持解析日期和時(shí)間。本篇博客將深入探討 Sim

    2024年02月09日
    瀏覽(47)
  • Java中日期時(shí)間格式化方法SimpleDateFormat和DateTimeFormatter使用完整示例及區(qū)別說明

    Java中日期時(shí)間格式化方法SimpleDateFormat和DateTimeFormatter使用完整示例及區(qū)別說明

    示例代碼: 示例截圖: ?這里完整的用兩種方法分別實(shí)現(xiàn)了日期和String的來回轉(zhuǎn)換,鑒于SimpleDateFormat早已過時(shí),且非線程安全,所以推薦大家首選使用DateTimeFormatter,用法基本都是差不多的。變化不大。但是DateTimeFormatter需要Java Level 8(8 - Lambdas, type annotations etc.),需留意。

    2023年04月09日
    瀏覽(26)
  • 【js】時(shí)間和時(shí)間戳轉(zhuǎn)換、日期格式化

    1、時(shí)間戳轉(zhuǎn)換日期方法 (格式:2023-08-17) 2、日期字符串轉(zhuǎn)時(shí)間戳 3、時(shí)間戳轉(zhuǎn)換日期+時(shí)間方法 date:時(shí)間戳數(shù)字(格式:2023-08-17 14:11:01) 4、 獲取日期中文格式

    2024年02月12日
    瀏覽(21)
  • 【JavaScript】JavaScript日期和時(shí)間的格式化:

    一、日期和時(shí)間的格式化 1、原生方法 【1】使用 toLocaleString 方法 【2】使用 Intl.DateTimeFormat 對(duì)象 2、使用字符串操作方法 3、自定義格式化函數(shù) 【1】不可指定格式的格式化函數(shù) 【2】可指定格式的格式化函數(shù) 4、使用第三方庫 二、日期和時(shí)間的其它常用處理方法 1、創(chuàng)建 Dat

    2024年02月10日
    瀏覽(96)
  • Flutter/Dart日期格式化及時(shí)間戳轉(zhuǎn)換

    點(diǎn)擊進(jìn)入我的自建博客鏈接 Dart 獲取當(dāng)前時(shí)間,以及獲取當(dāng)前年、月、日等。 創(chuàng)建指定時(shí)間還可以直接從符合日期格式的字符串直接轉(zhuǎn)換,如下。 日期字符串轉(zhuǎn)為時(shí)間 日期時(shí)間轉(zhuǎn)成時(shí)間戳 時(shí)間戳轉(zhuǎn)日期時(shí)間 可以給某個(gè)時(shí)間增加或減少時(shí)間段(Duration)。

    2024年02月11日
    瀏覽(24)
  • sqlite3日期時(shí)間格式化和自動(dòng)輸入

    Sqlite3系列:初步??where??select sqlite中并未提供單獨(dú)的日期時(shí)間類型,但提供了三種時(shí)間表示方式 通過text來存儲(chǔ)時(shí)間文本 用整型來存儲(chǔ)時(shí)間戳,時(shí)間戳是從1970-01-01算起的秒數(shù) 用浮點(diǎn)型來存儲(chǔ)自儒略日開始算起的天數(shù),儒略日即公元前4713年1月1日中午12點(diǎn)。 并且提供了一些

    2024年02月06日
    瀏覽(28)
  • JavaScript 日期和時(shí)間的格式化大匯總(收集)

    一、日期和時(shí)間的格式化 1、原生方法 1.1、使用 toLocaleString 方法 Date 對(duì)象有一個(gè) toLocaleString 方法,該方法可以根據(jù)本地時(shí)間和地區(qū)設(shè)置格式化日期時(shí)間。例如: ? toLocaleString 方法接受兩個(gè)參數(shù),第一個(gè)參數(shù)是地區(qū)設(shè)置,第二個(gè)參數(shù)是選項(xiàng),用于指定日期時(shí)間格式和時(shí)區(qū)信息

    2024年02月08日
    瀏覽(92)
  • Windows bat 批處理 日期時(shí)間格式化

    Windows bat 批處理 日期時(shí)間格式化

    有一個(gè)批處理腳本,腳本中根據(jù)當(dāng)前日期,動(dòng)態(tài)的生成日志文件, 如:當(dāng)前是 2023年06月20日,我希望生成的日志文件名為:XX_20230620.log Windows 在批處理中 獲取日期和時(shí)間的方式如下: echo %time% 輸出的時(shí)間格式: HH:MM:SS.NN HH :時(shí) MM :分 SS :秒 NN :厘秒(注意不是毫秒,1秒

    2024年02月11日
    瀏覽(26)
  • 日期格式化的最佳實(shí)踐:如何在Java中處理日期格式化

    日期格式化的最佳實(shí)踐:如何在Java中處理日期格式化

    當(dāng)涉及到日期格式化時(shí),了解正確的方式和最佳實(shí)踐是至關(guān)重要的。 日期格式化是將日期轉(zhuǎn)換為特定格式的過程,以便在應(yīng)用程序開發(fā)中更好地展示、存儲(chǔ)或交互。 以下內(nèi)容展示常用的三種方式 在Java中,你可以使用java.time.format.DateTimeFormatter類來格式化日期,并將格式化后

    2024年02月07日
    瀏覽(100)
  • 使用 uni-app 開發(fā)項(xiàng)目,日期和時(shí)間如何格式化?

    功能需求描述 在開發(fā)項(xiàng)目時(shí),往往需要對(duì)從后端查詢到的時(shí)間進(jìn)行格式化,查到的時(shí)間格式一般都是 時(shí)間戳 ,一堆數(shù)字,這時(shí)候怎么轉(zhuǎn)化成類似于? 2023年8月15日 08:12:10 ?這樣的格式? 在組件顯示格式化后的日期 其實(shí) uni-app 的官方拓展組件? uni-dateformat ?就能實(shí)現(xiàn)這個(gè)需求

    2024年02月05日
    瀏覽(12)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包