J2ME:从 DateField 中仅获取年/月/日

发布于 2024-09-26 16:09:39 字数 520 浏览 2 评论 0原文

我正在尝试使用 dateField 来显示日历中选择的年份、月份或日期。

public DateField getDateField() {
dateField = new DateField("dateField", DateField.DATE);
dateField.setDate(new java.util.Date(System.currentTimeMillis()));
}

然后我想使用此代码,但不是长日期“Thu Oct 07 00:00:00 GMT+02:00 2010”,我只想查看选择的月份,例如“十月”或“ 10”等。

String month = dateField.getDate().toString();
System.out.println("Selected month: " + month);

我在这个 dateField 上找不到任何好的东西...如果在 dateField 中选择了特定日期,我想获得像“2010-10-05”这样的短日期。

I'm trying to use dateField to display which year, month or day has been selected in the calendar.

public DateField getDateField() {
dateField = new DateField("dateField", DateField.DATE);
dateField.setDate(new java.util.Date(System.currentTimeMillis()));
}

Then I'd like to use this code, but instead of the long date "Thu Oct 07 00:00:00 GMT+02:00 2010" I would like to just see what month has been selected, like "October" or "10" etc.

String month = dateField.getDate().toString();
System.out.println("Selected month: " + month);

I can't find anything good on this dateField thing... I want to get the short date like "2010-10-05" if that specific date has been selected in the dateField.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

檐上三寸雪 2024-10-03 16:09:39
Calendar cal= Calendar.getInstance();
cal.setTime(dateField.getDate());
String date = cal.get(Calendar.YEAR) + "-" + ( cal.get(Calendar.MONTH) + 1 ) + "-" + cal.get(Calendar.DAY_OF_MONTH);
Calendar cal= Calendar.getInstance();
cal.setTime(dateField.getDate());
String date = cal.get(Calendar.YEAR) + "-" + ( cal.get(Calendar.MONTH) + 1 ) + "-" + cal.get(Calendar.DAY_OF_MONTH);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文