我如何写一个大家都看到的公共计时器?

问题描述 投票:0回答:1

我想在我的应用中实现一个计时器,该计时器显示新更新何时发布。Importand是使用我的应用程序的每个人都看到相同的计时器,并且剩余时间相同。

有人知道我该如何存档吗?

UPDATE:

到目前为止我尝试过:

SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss");
        formatter.setLenient(false);


        String endTime = "11.10.2019, 15:23:00";

        Date endDate;
        try {
            endDate = formatter.parse(endTime);
            timer = endDate.getTime();

        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (java.text.ParseException e) {
            e.printStackTrace();
        }

        startTime = System.currentTimeMillis();

        diff = timer - startTime;


        new CountDownTimer(timer, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {

                startTime=startTime-1;
                long serverUptimeSeconds =
                        (millisUntilFinished - startTime) / 1000;




                String  hms =  (String.format("%d", serverUptimeSeconds / 86400)+"d "+String.format("%d", (serverUptimeSeconds % 86400) / 3600)+"h "+ String.format("%d", ((serverUptimeSeconds % 86400) % 3600) / 60))+"m " + String.format("%d", ((serverUptimeSeconds % 86400) % 3600) % 60)+"s ";
                counter.setTitle(hms);

            }

它显示剩余时间,具体取决于我写的日期和时间

String endTime = "11.10.2019, 15:23:00";

以及用户时区。

如何归档每个人看到的剩余时间不是基于他们的时区,而是我的时区:GMT + 2?

java android timer long-integer
1个回答
0
投票
TimeZone tz = TimeZone.getTimeZone("GMT+02:00"); Calendar c = Calendar.getInstance(tz); String time = String.format("%02d" , c.get(Calendar.HOUR_OF_DAY))+":"+ String.format("%02d" , c.get(Calendar.MINUTE))+":"+ String.format("%02d" , c.get(Calendar.SECOND))+":"+ String.format("%03d" , c.get(Calendar.MILLISECOND));
© www.soinside.com 2019 - 2024. All rights reserved.