Here you can find the source of toBase(long startMillis, long currentMillis, long baseMillis)
public static long toBase(long startMillis, long currentMillis, long baseMillis)
//package com.java2s; //License from project: Open Source License public class Main { public static long toBase(long startMillis, long currentMillis, long baseMillis) { long low = downTo(currentMillis, baseMillis); long high = upTo(currentMillis, baseMillis); long ret = startMillis; while (ret <= low) { ret += baseMillis;// w w w.j a va 2s. c o m } while (ret >= high) { ret -= baseMillis; } return ret; } public static long downTo(long currentMillis, long baseMillis) { return currentMillis / baseMillis * baseMillis; } public static long upTo(long currentMillis, long baseMillis) { return downTo(currentMillis, baseMillis) + baseMillis; } }