Android examples for java.util:Time
get Next Clock Left Time Millis
import android.annotation.SuppressLint; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main{ public static long getNextClockLeftTimeMillis() { LogUtil.log("********** CURRENT TIME : [" + getDate(System.currentTimeMillis(), "yyyy/MM/dd HH:mm:ss") + "]"); Calendar next = Calendar.getInstance(); next.add(Calendar.HOUR_OF_DAY, 1); int hour = next.get(Calendar.HOUR_OF_DAY); next.set(Calendar.HOUR_OF_DAY, hour); next.set(Calendar.MINUTE, 0); next.set(Calendar.SECOND, 0); long nextTimeMillis = next.getTimeInMillis(); LogUtil.log("********** NEXT TIME : [" + getDate(nextTimeMillis, "yyyy/MM/dd HH:mm:ss") + "]"); return nextTimeMillis - System.currentTimeMillis(); }/*from w w w . j av a2 s. c o m*/ @SuppressLint("SimpleDateFormat") public static String getDate(long timeMillis) { return new SimpleDateFormat("yyyy/MM/dd").format(new Date( timeMillis)); } public static String getDate(long timeMillis, String strFormat) { return new SimpleDateFormat(strFormat).format(new Date(timeMillis)); } }