Java 如何向我的日期对象添加时间?

Java 如何向我的日期对象添加时间?,java,android,Java,Android,如何将时间添加到我使用日期选择器选择的日期对象。日期选择器默认将时间设置为00:00:00到我的日期对象,我需要将当前系统时间添加到我的日期对象 Calendar now = Calendar.getInstance(); int hours = now.get(Calendar.HOUR_OF_DAY); int minutes = now.get(Calendar.MINUTE); int seconds = now.get(Calendar.SECOND); //int hours = n

如何将时间添加到我使用日期选择器选择的日期对象。日期选择器默认将时间设置为
00:00:00
到我的日期对象,我需要将当前系统时间添加到我的日期对象

Calendar now = Calendar.getInstance();
int hours = now.get(Calendar.HOUR_OF_DAY);
int minutes = now.get(Calendar.MINUTE);
int seconds = now.get(Calendar.SECOND);
//int hours = new Time(System.currentTimeMillis()).getHours();
//int minutes = new Time(System.currentTimeMillis()).getMinutes();
//int seconds = new Time(System.currentTimeMillis()).getSeconds();
now.set(year, month, day, hours, minutes, seconds);
textDateField.setText(getDateAsString(now.getTime()));
我使用的是日期选择器,点击设置按钮,我会在字段中显示日期,但是日期对象没有时间。如何使用日期对象附加时间

public static String getDateAsString(Date date) {
    SimpleDateFormat format = new SimpleDateFormat("dd MMM yyyy");
    return format.format(date);
}

以上是我尝试过的,但它不起作用。

要使时间也显示在您的字段中,您只需将其添加到您的
SimpleDataFormat

public static String getDateAsString(final Date date) {
    SimpleDateFormat format = new SimpleDateFormat("dd MMM yyyy HH:mm:ss");
    return format.format(date);
}

问题出在输出的格式上了吗?@Keppil:不,我的文本字段只显示日期,但当我发送到服务时,它应该包含日期和时间。这是我正在尝试的内容的粘贴。。。。当我试图从date对象获取时间时,我无法获取时间始终为00:00:00。您从哪里获取
00:00:00
?您正在格式化它,没有时间。只需实例化new Date()即可获取当前时间。现在日期=新日期();然后使用上面写的方法格式化它。我在另一个地方显示它,在那里我尝试从这个日期对象获取时间。String time=localDateFormat.format(Utils.getDate(thisDateObject);//thisDateObject始终具有00:00:00,无论我们向其添加时间如何。请向我们展示问题中包含的所有代码,我们在这里玩猜谜游戏。