Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the countdown to time by Java

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "Java how to achieve the countdown minutes", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Java how to achieve countdown minutes" bar!

Package com.test;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Timer;import java.util.TimerTask;/** * multitask timer * * / public class Testsss {public final static Map map = new HashMap () Public static void main (String [] args) {String nowdate = "2019-09-09 10:28:17"; String startdate = "2019-09-09 10:28:20"; Date nowdate1 = parseToDateTime (nowdate, "yyyy-MM-dd HH:mm:ss"); Date startdate1 = parseToDateTime (startdate, "yyyy-MM-dd HH:mm:ss") String nowdate2 = "2019-09-09 10:20:17"; String startdate2 = "2019-09-09 10:20:21"; Date nowdate12 = parseToDateTime (nowdate2, "yyyy-MM-dd HH:mm:ss"); Date startdate12 = parseToDateTime (startdate2, "yyyy-MM-dd HH:mm:ss") Int deff = getBetweenTimes (nowdate1,startdate1); System.out.println (deff); int deff2 = getBetweenTimes (nowdate12,startdate12); System.out.println (deff2); map.put ("id1", String.valueOf (deff)); map.put ("id2", String.valueOf (deff2)) Timer timer = new Timer (); timer.schedule (new TimerTask () {@ Override public void run () {System.out.println ("timer....") Iterator entries = map.entrySet () .iterator (); while (entries.hasNext ()) {Map.Entry entry = (Map.Entry) entries.next (); String taskId = (String) entry.getKey () String time = (String) entry.getValue (); int times = Integer.parseInt (time); if (times > = 0) {times-- Map.put (taskId,String.valueOf (times)); System.out.println (taskId+ "- >" + framt (Integer.parseInt (time) } else {map.remove (taskId) } if (map.size () = = 0) {System.out.println ("done"); timer.cancel () }, 0P.1000) } / * seconds turn minute * * @ param seconds * / public static String framt (int seconds) {int temp=0; StringBuffer sb=new StringBuffer () Temp = seconds/3600; sb.append ((temp

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report