本文介紹了簡單日期格式.返回錯(cuò)誤日期的格式的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我有這段代碼我想知道為什么它返回正確的日期
I have this code I would like to know why it returns correct date
Festival f= (Festival) festival.get(0);
Date d=f.getSDate();
System.out.println(d.getYear());
System.out.println(d.getMonth());
System.out.println(d.getDate());
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); // define your format.
String formattedDate = df.format(d);
System.out.println("New Date To Show::"+formattedDate);
輸出是這樣的
2019
2
27
New Date To Show::27/03/3919
推薦答案
試試這個(gè):
Date date=new Date();
// you can assign your return from the function here
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
System.out.println(localDate.getMonthValue());
System.out.println(localDate.getDayOfMonth());
System.out.println(localDate.getYear());
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String formattedDate = df.format(date);
System.out.println("New Date To Show::"+formattedDate);
這篇關(guān)于簡單日期格式.返回錯(cuò)誤日期的格式的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!