我想在我的 Android 应用程序中设置日期和时间。日期应为今天的日期,但文本字段中的时间应默认设置为早上 6:00。我已经阅读了很多链接,但其中大部分都显示了今天的时间和日期(例如:2016-03-28 11:53:55)。
String timetxt1 = "06:00:00";
Date datetxt1 = null;;
try {
datetxt1 = simpleDateFormat.parse(timetxt1);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar selectedDate1 = Calendar.getInstance();
selectedDate1.setTime(datetxt1);
edittxt.setText(dateFormatter.format(selectedDate1.getTime()));
最佳答案
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 6);// for 6 hour
calendar.set(Calendar.MINUTE, 0);// for 0 min
calendar.set(Calendar.SECOND, 0);// for 0 sec
System.out.println(calendar.getTime());// print 'Mon Mar 28 06:00:00 ALMT 2016'
关于java - 在 Android 中设置日期和所需时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36257085/