Вы могли сделать то, что делает Google. Который является после определенного числа попыток у них есть captacha, обнаруживаются. Чем после пару раз с captacha Вы блокируете их в течение нескольких минут.
Joda Time (как всегда) значительно упрощает эту задачу благодаря методу DateTimeZone.nextTransition
. Например:
import org.joda.time.*;
import org.joda.time.format.*;
public class Test
{
public static void main(String[] args)
{
DateTimeZone zone = DateTimeZone.forID("Europe/London");
DateTimeFormatter format = DateTimeFormat.mediumDateTime();
long current = System.currentTimeMillis();
for (int i=0; i < 100; i++)
{
long next = zone.nextTransition(current);
if (current == next)
{
break;
}
System.out.println (format.print(next) + " Into DST? "
+ !zone.isStandardOffset(next));
current = next;
}
}
}
Вывод:
25-Oct-2009 01:00:00 Into DST? false 28-Mar-2010 02:00:00 Into DST? true 31-Oct-2010 01:00:00 Into DST? false 27-Mar-2011 02:00:00 Into DST? true 30-Oct-2011 01:00:00 Into DST? false 25-Mar-2012 02:00:00 Into DST? true 28-Oct-2012 01:00:00 Into DST? false 31-Mar-2013 02:00:00 Into DST? true 27-Oct-2013 01:00:00 Into DST? false 30-Mar-2014 02:00:00 Into DST? true 26-Oct-2014 01:00:00 Into DST? false 29-Mar-2015 02:00:00 Into DST? true 25-Oct-2015 01:00:00 Into DST? false ...
В Java 8 вы можете получить ту же информацию, используя ZoneRules
с его методами nextTransition
и previousTransition
.