enter image description here我有很多国家和各自的时间。如果我们的本地时间和国家/地区时间相同,则应显示与所有国家/地区相关的信息。 谁能帮我写一段代码,并上传国家时间Excel表格。 谢谢。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.");
}
}
答案 0 :(得分:0)
我找到了解决方案。
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();
}