API Date .
(15 ) . 15- . , . . :
import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
long ms = new Date().getTime();
System.out.println("Current time: " + new Date().toString());
long fifteen = 15 * 60 * 1000;
long newMs = (ms / fifteen) * fifteen + fifteen;
System.out.println("Calculated time: " + new Date(newMs));
}
}
.
:
LocalDate
import java.util.*;
import java.lang.*;
import java.io.*;
import java.time.*;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
LocalTime now = LocalTime.now();
System.out.println(now);
LocalTime next = now.with((temp) -> {
int currentMinute = temp.get(ChronoField.MINUTE_OF_DAY);
int interval = (currentMinute / 15) * 15 + 15;
temp = temp.with(ChronoField.SECOND_OF_MINUTE, 0);
temp = temp.with(ChronoField.MILLI_OF_SECOND, 0);
return temp.with(ChronoField.MINUTE_OF_DAY, interval);
});
System.out.println(next);
}
}