JavaDemo——获得指定时间与当前时间最近的时间差

demo:

/**
 * 2018年9月27日下午4:26:21
 */
package testTimeDifference;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author XWF
 *
 */
public class TestTimeDifference {

	/**
	 * @param args
	 * @throws InterruptedException 
	 * @throws ParseException 
	 */
	@SuppressWarnings("deprecation")
	public static void main(String[] args) throws InterruptedException, ParseException {
		String t = "12:26";
		for(int i=0;i<20;i++) {
			Thread.sleep(200);
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
			Date dtemp = sdf.parse(t);
			Date dnow = new Date();
			dtemp.setYear(dnow.getYear());
			dtemp.setMonth(dnow.getMonth());
			dtemp.setDate(dnow.getDate());
			long msecondes = 0;
			if(dtemp.getTime()

结果:

JavaDemo——获得指定时间与当前时间最近的时间差_第1张图片

你可能感兴趣的:(JavaDemos)