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

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

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

問題描述

限時送ChatGPT賬號..

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

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) 構(gòu)造函數(shù)可以正常工作.當(dāng)然,該構(gòu)造函數(shù)已被折舊,我想避免在我正在編寫的新代碼中使用折舊調(diào)用.然而,解決這個簡單問題的所有其他選項似乎都非常復(fù)雜.如果不使用折舊的構(gòu)造函數(shù),真的沒有簡單的方法可以做我想做的事嗎?

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 日期相關(guān)問題的標(biāo)準(zhǔn)答案是使用 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 您提到的,正是建議的內(nèi)容:

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 :-).

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

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

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
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 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 四虎永久在线视频 | 欧美精品日韩少妇 | 看免费毛片 | 少妇一级淫片 | 黄色网址免费看 | 色婷婷在线视频 | 成人在线观看网站 | 超碰免费公开 | 97色在线| 国产一级在线视频 | 欧美a一级 | 午夜网站在线观看 | 亚洲另类av | 欧美日韩一区二 | 精品国产91乱码一区二区三区 | av男人天堂网 | 91av免费 | 亚洲精选一区 | 69福利视频 | 超碰在线中文字幕 | 亚洲小视频在线观看 | 国产乱码一区二区 | 手机av在线 | 国产精品福利视频 | 欧美日韩一区二区三区视频 | 天天操夜夜骑 | a视频在线观看 | 欧美精品在线观看视频 | 欧美不卡一区二区三区 | 午夜在线视频 | 欧美成人精品一区二区三区 | 国产午夜精品久久久久久久 | 一区二区亚洲 | 国产女人18毛片水18精品 | 91禁蘑菇在线看 | av网站观看| 91成人国产 | 黄色片久久 | 97色婷婷| 国内精品久久久久久久久 | 欧美性影院 |