Android如何显示优惠结束时间计数器?(Android How to show offers end time counter?)

编程入门 行业动态 更新时间:2024-10-28 19:26:46
Android如何显示优惠结束时间计数器?(Android How to show offers end time counter?)

我试图在我的应用程序中显示一些提供结束时间计数器,它从我的后端获取结束时间字符串,并假设显示剩余天数:小时:分钟:通过将它与当前日期进行比较但我真的迷路了!

我希望有人能够通过它

她是我的代码:

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.tv); String offerenddate = "2017-04-01 12:56:50"; final SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); try { Date oldDate = dateFormat.parse(offerenddate); Date currentDate = new Date(); long diff = oldDate.getTime() - currentDate.getTime(); long seconds = diff / 1000; final long minutes = seconds / 60; final long hours = minutes / 60; final long days = hours / 24; new CountDownTimer( diff,1000) { @Override public void onTick(long l) { tv.setText("Time Remaining : "+days+" - "+hours+":"+minutes); } @Override public void onFinish() { tv.setText("Closed"); } }.start(); } catch (Exception e) { e.printStackTrace(); } } }

I'm trying to show some offer end time counter in my app which takes the end time string from my backend and its suppose to display the remaining days:hours:minutes:seconds by comparing it with current date but i really get lost !!

i hope that some one go through it

her is my code:

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.tv); String offerenddate = "2017-04-01 12:56:50"; final SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); try { Date oldDate = dateFormat.parse(offerenddate); Date currentDate = new Date(); long diff = oldDate.getTime() - currentDate.getTime(); long seconds = diff / 1000; final long minutes = seconds / 60; final long hours = minutes / 60; final long days = hours / 24; new CountDownTimer( diff,1000) { @Override public void onTick(long l) { tv.setText("Time Remaining : "+days+" - "+hours+":"+minutes); } @Override public void onFinish() { tv.setText("Closed"); } }.start(); } catch (Exception e) { e.printStackTrace(); } } }

最满意答案

您可以使用Library,countdownView https://github.com/iwgang/CountdownView 。

You may use the Library,countdownView https://github.com/iwgang/CountdownView.

更多推荐

本文发布于:2023-07-24 07:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1243429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计数器   结束时间   Android   show   counter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!