private TimeCount btnGetIdentifyTimeCount; // 验证码读秒
// 获取验证码读秒
class TimeCount extends CountDownTimer {
private String btnTitle;
public TimeCount(long millisInFuture, long countDownInterval, String btnTitle) {
super(millisInFuture, countDownInterval);// 参数依次为总时长,和计时的时间间隔
this.btnTitle = btnTitle;
}
@Override
public void onFinish() { // 计时完毕时触发
btnGetIdentify.setText(btnTitle);
btnGetIdentify.setClickable(true);
@Override
public void onTick(long millisUntilFinished) {// 计时过程显示
btnGetIdentify.setClickable(false);
btnGetIdentify.setText(millisUntilFinished / 1000 + "秒");
}
}
btnGetIdentifyTimeCount = new TimeCount(60000, 1000, "获取验证码");
btnGetIdentifyTimeCount.start();
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
// 倒计时
if (!"".equals(data.getOrderTime())) {
try {
String orderDate = data.getOrderTime().substring(0, 19);
SimpleDateFormat formatter = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
Date myDate = formatter.parse(orderDate);
Calendar c = Calendar.getInstance();
c.setTime(myDate);
c.add(Calendar.HOUR, 1);
int currentTime = (int) (System.currentTimeMillis() / 1000);
int endTimes = (int) (c.getTimeInMillis() / 1000)
- currentTime; // serverTime;//
// System.out.println("orderDate: "+(int)(c.getTimeInMillis()/1000));
// System.out.println("currentTime: "+currentTime);
// System.out.println("endTimes: "+endTimes);
// System.out.println(formatter.format(myDate));
if (endTimes > 0 && endTimes < 60 * 60) {
holder.ivClock.setVisibility(View.VISIBLE);
holder.tvMinute.setVisibility(View.VISIBLE);
StringBuffer sb = new StringBuffer();
int nd = 24 * 60 * 60 * 100;// 一天的毫秒数
int nh = 60 * 60 * 100;// 一小时的毫秒数
int nm = 60;// 一分钟的毫秒数
int ns = 1;// 一秒钟的毫秒数
long day = endTimes / nd;// 计算差多少天
long hour = endTimes % nd / nh + day * 24;// 计算差多少小时
long min = endTimes / nm;// 计算差多少分钟
long sec = endTimes % nm;// 计算差多少秒
// if (day > 0 || hour - day * 24 > 0 || min - day *
// 24 * 60 > 0) {
if (min > 9) {
sb.append(min);
mins = min + ":";
} else {
sb.append("0" + (min));
mins = "0" + min + ":";
sb.append(":");
}
if (sec > 9) {
sb.append(sec);
secs = sec + "";
} else {
sb.append("0" + sec);
secs = "0" + sec;
}
holder.tvMinute.setText(mins + secs);
} else {
holder.ivClock.setVisibility(View.GONE);
holder.tvMinute.setVisibility(View.GONE);
holder.tvPayTime.setVisibility(view.INVISIBLE);
holder.btnPay
.setBackgroundResource(R.drawable.ic_over_enroll);
holder.tvOrderTime.setText(data.getOrderTime()
.subSequence(0, 10));
}
} catch (Exception e) {
e.printStackTrace();
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章