从系统时钟设置自己。倒计时到第二天凌晨2点。假设您启动应用程序时是晚上 11 点。在 main.xml 上运行 3 小时倒计时这是我到目前为止所拥有的
import java.util.Calendar;
import java.util.GregorianCalendar;
import android.app.Activity;
public class LastCall extends Activity {
public static void main(String[] args){
Calendar calendar = new GregorianCalendar();
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int timelefthour = 0;
int timeleftmin = 0;
if(calendar.get(Calendar.AM_PM) == 1 && hour != 12)
timelefthour = (12 - hour) + 2;
timeleftmin = 60 - minute;
if(calendar.get(Calendar.AM_PM) == 1 && hour == 12)
timelefthour = 13;
timeleftmin = 60 - minute;
if(calendar.get(Calendar.AM_PM) == 0 && hour == 12)
timelefthour = 1;
timeleftmin = 60 - minute;
if(calendar.get(Calendar.AM_PM) == 0 && hour <= 2)
timelefthour = 2 - hour;
timeleftmin = 60 - minute;
String lastcall = (Integer.toString(timelefthour) + " hr " + Integer.toString(timeleftmin) + " min ");
}
}