-1

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

}

}

rahul
  • 1
  • 4
  • Can you explain your requirement clearly? By clearly, I mean to provide your input, required output with examples, and your current code – Phenomenal One Dec 06 '18 at 11:07
  • 1
    Don’t post images of code. It’s much nicer to have the code in the question, as you also have. – Ole V.V. Dec 06 '18 at 11:14
  • I have a different different country and their related timing like japan have 400(4am) america 600(6am) and india have 1200(12am) pakistan (1400)2pm. and right now our local time is 4:45 so those country belongs to 4 o;clock those country we want. – rahul Dec 06 '18 at 11:14
  • above code is my latest code. – rahul Dec 06 '18 at 11:15
  • I can’t understand your code. Tips: (1) Since you can use java.time, the modern Java date and time API, do that exclusively. Don’t use the old `TimeZone` class, use `ZoneId` instead. (2) `LocalDateTime.parse(LocalDateTime.now().toString())` does the same as just `LocalDateTime.now()`. – Ole V.V. Dec 06 '18 at 11:16
  • You get the local time zone (more precisely, the JVM time zone setting) from `ZoneId.systemDefault()`. I would suspect that you could best use this for looking up the country in the Excel data and not use the current time (“now”). – Ole V.V. Dec 06 '18 at 11:18
  • yeah i got it i did that one but how to compare GMTTIMEOf every country and our local time if it is same then all related country should be displayed. – rahul Dec 06 '18 at 11:25
  • i did that one ---> LocalDateTime dateTime = LocalDateTime.parse(LocalDateTime.now().toString()) String actultime = String.valueOf(dateTime.getHour() * 100); – rahul Dec 06 '18 at 11:25
  • I'm neither understanding your code nor your requirements. What's the "time of a country" for any of the countries that span multiple timezones? As the code mentions "scheduler": You should store and calculate timestamps in UTC only, this makes calculations so much easier. Separate concerns like "where in the world is this" and "when should something be executed (in UTC)". – Olaf Kock Dec 07 '18 at 11:01
  • thanks Olaf i got the solution. – rahul Dec 08 '18 at 20:05

1 Answers1

0

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();
    }
Hearen
  • 7,420
  • 4
  • 53
  • 63
rahul
  • 1
  • 4