View Full Version : problem with getting current date and time

30 Jul 2010, 6:32 AM
hello every one,
i have DateField for the date and TextField fro the hour:

DateField fin = new DateField();
right.add(fin, formData);
TextField fTime = new TextFieldMask();
after that i have the function for converting them:

private Date convertDateField(Date date, String time) {
String fullDateTime = DateTimeFormat.getFormat("yyyy-mm-dd").format(date)+ " " + time;
return DateTimeFormat.getFormat(pFormat).parse(fullDateTime);
and the result like that: Fri Jul 30 22:11:10 CEST 2010
my problem is that i want to compare this result with the current date and time of the system, but i don't know how to get them (current date and time of the system) in my format :
("yyyy-mm-dd").format(date)+ " " + time
if you have some ideas ???

30 Jul 2010, 6:46 AM
Have you tried

DateTimeFormat.getFormat(pFormat).format(new Date());

2 Aug 2010, 1:46 AM
thank's for your answer, i tried the code that you wrote, it works and the result is
today date 2010-35-02 11:35:50
but i still can't compare it with my data because the return type of your code is String and not Date, and i can't cast it to Date.
i have

Date start = new Date();
start = mission.getOuverture().getPeriodStartTime();

Date periodStartTime = convertDateField(debut.getValue(), dTime.getValue());
and convertDateField is my function above

private Date convertDateField(Date date, String time) {
String fullDateTime = DateTimeFormat.getFormat("yyyy-mm-dd").format(
+ " " + time;
return DateTimeFormat.getFormat(pFormat).parse(fullDateTime);

public String pFormat = "yyyy-mm-dd HH:mm:ss";
thank's for your help

2 Aug 2010, 2:19 AM

For getting the current date:
Date currentDate = new Date();

Is that what you want? Sorry, but this is basic java :-)

2 Aug 2010, 3:38 AM