我想在我的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()));
Run Code Online (Sandbox Code Playgroud)
mmu*_*hid 13
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'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14911 次 |
| 最近记录: |