久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

替換 java.util.Date(year,month,day) 的公認方法是什么

What is the accepted way to replace java.util.Date(year,month,day)(替換 java.util.Date(year,month,day) 的公認方法是什么)
本文介紹了替換 java.util.Date(year,month,day) 的公認方法是什么的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試做一些非常簡單的事情,但開始意識到 Java 中的日期有點雷區.我想要的只是通過三個整數組(一年、一個月和一個日期)創建一些 Date 對象,對它們進行一些簡單的測試(沿著日期 B 之前的日期 A并且在 1990 年 1 月 1 日之后),將它們轉換為 java.sql.Date 對象并通過 JDBC 將它們傳遞給數據庫.

I'm trying to do something really simple, but starting to realize that dates in Java are a bit of minefield. All I want is to get passed groups of three ints ( a year, a month and a date) create some Date objects, do some simple test on them (along the lines of as date A before date B and after January 1 1990), convert them to java.sql.Date objects and pass them off to the database via JDBC.

一切都非常簡單,使用 java.util.Date(int year,int month,int day) 構造函數可以正常工作.當然,該構造函數已被折舊,我想避免在我正在編寫的新代碼中使用折舊調用.然而,解決這個簡單問題的所有其他選項似乎都非常復雜.如果不使用折舊的構造函數,真的沒有簡單的方法可以做我想做的事嗎?

All very simple and works fine using the java.util.Date(int year,int month,int day) constructor. Of course that constructor is depreciated, and I'd like to avoid using depreciated calls in new code I'm writing. However all the other options to solve this simple problem seem stupidly complicated. Is there really no simple way to do what I want without using depreciated constructors?

我知道所有 Java 日期相關問題的標準答案是使用 joda 時間",但我真的不想因為這樣一個看似微不足道的問題而開始使用第三方庫.

I know the standard answer to all Java date related questions is "use joda time", but I really don't want to start pulling in third party libraries for such a seemingly trivial problem.

推薦答案

想法是使用 Calendar 類,像這樣:

The idea is to use the Calendar class, like so:

Calendar cal = Calendar.getInstance();
cal.set(year, month, date);
Date date = cal.getTime();

確實,如果您檢查 constructor 您提到的,正是建議的內容:

Indeed, if you check the Javadoc of the constructor you are mentioning, it is exactly what is suggested:

Date(int year, int month, int date)
          Deprecated. As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date) or GregorianCalendar(year + 1900, month, date).

或者...使用 JodaTime :-).

Or ... use JodaTime :-).

這篇關于替換 java.util.Date(year,month,day) 的公認方法是什么的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 综合久久综合久久 | 性做久久久久久免费观看欧美 | 久久大陆 | 涩涩导航| 欧美午夜精品久久久久久浪潮 | 一区网站| 亚洲一区二区三区在线 | 欧美日本亚洲 | 亚洲第一视频网 | 久久神马| 中文字幕一区二区三区四区五区 | 日韩精品在线免费观看视频 | 亚洲国产成人精品女人 | 久久国产精品视频 | 日本电影网站 | 999精品在线| 精品中文字幕在线观看 | 午夜理伦三级理论三级在线观看 | 久久成人高清视频 | 一区二区精品在线 | 亚洲av毛片 | 久久影院一区 | 国产精品视频久久久 | 欧美日韩在线一区二区三区 | 国产有码 | 国产一区二区三区四区 | 国产美女精品视频免费观看 | 欧美福利精品 | 91精品久久久久久久久久 | 综合久久亚洲 | 欧美在线不卡 | 五月激情婷婷六月 | 日韩精品在线免费观看视频 | 欧美激情va永久在线播放 | 美女天天干天天操 | 自拍亚洲 | 色一级| 国产一区二区三区在线 | 欧美一区二区三区在线播放 | 日日操日日干 | 亚洲不卡在线观看 |