这是我的情况。方法 TodayFirst 我想获取每天上午 9:00 并与 Android 系统时间进行比较。但是我运行这个方法它会得到系统时间。
public String TodayFirst()
{
String time ="";
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(df.format(date));
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.HOUR_OF_DAY,9);
time = df.format(calendar.getTime());
}
You could do as belows:
public String TodayFirst()
{
String time;
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(df.format(date));
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.HOUR_OF_DAY,9);
calendar.set(calendar.MINUTE,0);
calendar.set(calendar.SECOND,0);
time = df.format(calendar.getTime());
return time; //time will be 2018/08/28 09:00:00 if you call the function today
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句