Imagine two widgets:
DateTime dtDate = new DateTime(parent, SWT.BORDER);
and
DateTime dtTime = new DateTime(parent, SWT.BORDER | SWT.TIME);
Would would be the most efficient way to read date and time from the two widgets into a single Date variable?
Edit: The following solution that I have in mind is far from being elegant. I hope that there is a better way to do this.
final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// year
dateString += String.valueOf(dtDate .getYear());
dateString += "-";
// month
dateString += String.valueOf(dtDate .getMonth());
dateString += "-";
// day
dateString += String.valueOf(dtDate .getDay());
dateString += " ";
// hour
dateString += String.valueOf(dtTime.getHours());
dateString += ":";
// minute
dateString += String.valueOf(dtTime.getMinutes());
dateString += ":";
// second
dateString += String.valueOf(dtTime.getSeconds());
try {
Date startDate = (Date) dateFormat.parse(dateString);
} catch (ParseException exception) {
exception.printStackTrace();
}