Skip to content

Instantly share code, notes, and snippets.

@ysmintor
Created March 24, 2017 03:03
Show Gist options
  • Save ysmintor/82208f86508787e3f1fd0d67cad1d64d to your computer and use it in GitHub Desktop.
Save ysmintor/82208f86508787e3f1fd0d67cad1d64d to your computer and use it in GitHub Desktop.
count down timer diff is long within milliseconds
/*Observable.interval(1, TimeUnit.SECONDS)
.take((int) (diff/SECOND_IN_MILLIS))
.flatMap(new Func1<Long, Observable<String>>() {
@Override
public Observable<String> call(Long aLong) {
long millisUntilFinished = diff - aLong * SECOND_IN_MILLIS;
long day = millisUntilFinished / (24 * 60 * 60 * SECOND_IN_MILLIS);
long hour = (millisUntilFinished / (60 * 60 * SECOND_IN_MILLIS) - day * 24);
long min = ((millisUntilFinished / (60 * SECOND_IN_MILLIS)) - day * 24 * 60 - hour * 60);
long s = (millisUntilFinished / SECOND_IN_MILLIS - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
return Observable.just("" + day + "天" + hour + "小时" + min + "分" + s + "秒");
}
})
.observeOn(AndroidSchedulers.mainThread())
.compose(this.<String>bindToLifecycle())
.subscribe(new BaseSubscriber<String>() {
@Override
protected void onError(ApiException ex) {
ToastUtil.showShort(mContext, ex.message);
}
@Override
public void onCompleted() {
// mBinding.tvLeftTime.setText("done!");
}
@Override
public void onNext(String result) {
mBinding.tvLeftTime.setText(result);
}
});*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment