I know this might be a simple question but Im new to Java, my experience is mostly with PHP or C#.
Im working on an eclipse RCP project and using Google Window Builder.
All I need to do is get the date from a DateTime control named: dateTimeDOB
It must return the date in this format (dd/mm/yyyy) if the day or month value is a single digit it must have a preceding "0".
I think the DateTime control Type is
org.eclipse.swt.widgets.DateTime
so for example:
String strDate = dateTimeDOB.getDate("dd/mm/yyyy");
thanks in advance
The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format.
The DateTimePicker control allows the user to select or display date and time values with a specified format in Windows Forms. Furthermore, we can determine the current date and time using the Value property of the DateTimePicker control.
In Windows Forms, the DateTimePicker control is used to select and display the date/time with a specific format in your form.
A cleaner approach (IMHO):
Calendar instance = Calendar.getInstance();
instance.set(Calendar.DAY_OF_MONTH, dateTimeDOB.getDay());
instance.set(Calendar.MONTH, dateTimeDOB.getMonth());
instance.set(Calendar.YEAR, dateTimeDOB.getYear());
String dateString = new SimpleDateFormat("dd/MM/yyyy").format(instance.getTime());
DateTime dateTimeDOB = ...
int day = dateTimeDOB.getDay();
int month = dateTimeDOB.getMonth() + 1;
int year = dateTimeDOB.getYear();
String strDate = (day < 10) ? "0" + day + "/" : day + "/";
strDate += (month < 10) ? "0" + month + "/" : month + "/";
strDate += year;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With