我想根据我们当地的时间来确定这个国家

ggazkfy8  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(404)

在这里输入图像描述我有这么多的国家和自己的时间。如果我们的本地时间和国家/地区时间相同,则应显示与所有国家/地区相关的时间。谁能帮我写一段代码和上传国家计时excel表也。感谢您的帮助。请在此处输入图像描述

public void countryBased() {
    LocalDateTime dateTime = LocalDateTime.parse(LocalDateTime.now().toString());
    TimeZone gmtTime=TimeZone.getTimeZone("GMT"+00);
    System.out.println("gmtTime new-->" + gmtTime);

    System.out.println("dateTime-->" + dateTime);
    /*
     * SchedulerRunTimes schedulerRunTime =
     * SchedulerRunTimesLocalServiceUtil
     * .createSchedulerRunTimes(CounterLocalServiceUtil.increment());
     */
    List<SchedulerRunTimes> schedulerRunTime = SchedulerRunTimesLocalServiceUtil.getSchedulerRunTimeses(-1, -1);
    /*
     * schedulerRunTime.setLOCAL_STANDARD_TIME(String.valueOf(dateTime.
     * getHour() * 100));
     */
    for (SchedulerRunTimes schedulerRunTimes : schedulerRunTime) {
        String GMTRunTime = schedulerRunTimes.getGMTRunTime();
        System.out.println(GMTRunTime);
        String datetimes = (String.valueOf(dateTime.getHour()+00));
        /*if (gmtTime.equals(GMTRunTime)) {
            trigger(schedulerRunTimes);
        } else {
            System.out.println("time Mismatch");
        }*/
    }
}

private void trigger(SchedulerRunTimes runTimes) {
    _log.info(runTimes.getCountryName() + " is triggered.");
    _log.info(runTimes.getCountryCode() + " is triggered.");

}

}

zmeyuzjn

zmeyuzjn1#

我找到解决办法了。

try {
        LocalDateTime dateTime = LocalDateTime.parse(LocalDateTime.now().toString());

        String GMTTiming = String.valueOf(dateTime.getHour() * 100);

        _log.info("GMT Time for Country-->" + GMTTiming);

        List<SchedulerRunTimes> schedulerRunTime = SchedulerRunTimesLocalServiceUtil.getSchedulerRunTimeses(-1, -1);

        for (SchedulerRunTimes schedulerRunTimes : schedulerRunTime) {
            String GMTRunTime = schedulerRunTimes.getGMTRunTime();
            _log.info("GMTRunTime-->" + GMTRunTime);

            _log.info("Compairing GMT Timing --------------->"
                    + GMTTiming.trim().equalsIgnoreCase(GMTRunTime.trim()));

            if (GMTTiming.trim().equalsIgnoreCase(GMTRunTime.trim())) {

                PurchasePrice.triggerCountry(schedulerRunTimes);
            } else {

                _log.info("Time is Different and Country Not Found");
            }
        }
        throw new CountryNotFoundException("Time is Different and Country Not Found");
    } catch (CountryNotFoundException e) {

        e.printStackTrace();
    }

相关问题