问题描述
我对java很新,我希望用户输入需要安排足球比赛的时间和日期。我正在使用SWING jForm作为界面。获得该日期之后,我也想把它放在数据库中。搜索很多,我无法搜索正确的代码,或者我不明白。我在一个很长的项目上工作,没有时间看教程。在这方面的任何帮助将非常感激。或者只是告诉我,如果我在字符串中有YYYY / MM / DD HH:MM:ss:SSS那么如何将它转换为日期格式?
日期d =(日期)dateString没有工作。
注意我正在使用拖放功能在jFrame上创建项目。
(a)在最后一刻进行日期工作是一个坏主意。日期时间可能是一个惊人的棘手话题。
(b)请参阅,是与Java捆绑的恶名昭彰的java.util.Date/Calendar类的流行替代品。
该代码只是您需要的代码,但您需要:
- 根据您的特定需要调整格式
- 将时区调整为您正在处理的任何
在Joda-Time框架内完成大部分日期工作。在开始和结束时,在Joda-Time DateTime对象和java.util.Date对象之间进行转换。 StackOverflow上的许多Q& A可以向您显示转换。
I am very new to java and I want user to input time and date on which a football match needs to be scheduled. I'm using SWING jForm as the interface. After getting that date I also want to put that in the database. After searching a lot either I couldn't search the right code or I can't understand that. I'm working on a pretty long project and left with no time to watch tutorial. Any help in this regard would be very highly appreciated.
Or just tell me if I have "YYYY/MM/DD HH:MM:ss:SSS" in a String then how can I convert that to Date format?
Date d = (Date)dateString didn't worked.
Note I am using drag and drop to create items on jFrame.
(a) Doing date-time work at the last minute is a bad idea. Date-time can be a surprisingly thorny topic.
(b) See my answer to a similar question.
My example code there uses the third-party library Joda-Time, a popular replacement for the notoriously bad java.util.Date/Calendar classes bundled with Java.
That code is just what you need, though you'll need to:
- Adjust the format to your particular needs
- Adjust the time zones to whatever you are handling
Do most of your date-time work within the Joda-Time framework. At the beginning and end, convert between Joda-Time DateTime objects and java.util.Date objects. Lots of Q&A here on StackOverflow to show you that conversion.
这篇关于日期和时间选择器在java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!