javajava-8timezoneliferay-7liferay-6.2

i want to fetch country based on our local timing


enter image description hereI have a so many countries and their own timing. if our local timing and country timing is same then related to all country should be displayed. can anyone please help i have written piece of code and uploading country timing Excel sheet also. thanks in advanced.enter image description here

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.");

}

}


Solution

  • i got the solution.

       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();
        }