DateTime?は日付・時刻の入出力を行えるウィジェットです date = new DateTime(composite, SWT.DATE); // 日付ウィジェットの場合 time = new DateTime(composite, SWT.TIME); // 時刻ウィジェットの場合 TIPS集。 †DateTime?のウィジェットに時刻や日付データを反映させるサンプルです。 public static void str2TimeWidget(DateTime dateTime, String timeStr, String[] pattern) { String[] patternTmp = new String[] { "HHmm", "HH:mm" }; if (pattern != null) { patternTmp = pattern; } try { Date parseDate = DateUtils.parseDate(timeStr, patternTmp); Calendar cal = Calendar.getInstance(); cal.setTime(parseDate); int hours = cal.get(Calendar.HOUR_OF_DAY); int minutes = cal.get(Calendar.MINUTE); int seconds = cal.get(Calendar.SECOND); dateTime.setTime(hours, minutes, seconds); } catch (ParseException e) { e.printStackTrace(); dateTime.setTime(0, 0, 0); } } public static void str2TimeWidget(DateTime dateTime, String timeStr) { str2TimeWidget(dateTime, timeStr, null); } public static void str2DateWidget(DateTime dateTime, String dateStr, String[] pattern) { String[] patternTmp = new String[] { "yyyyMMdd", "yyyy/MM/dd" }; if (pattern != null) { patternTmp = pattern; } try { Date date = DateUtils.parseDate(dateStr, patternTmp); Calendar cal = Calendar.getInstance(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = Calendar.DAY_OF_MONTH; dateTime.setDate(year, month, cal.get(day)); } catch (ParseException e) { e.printStackTrace(); } } public static void str2DateWidget(DateTime dateTime, String dateStr) { str2DateWidget(dateTime, dateStr, null); } この記事は 現在のアクセス:8246 |