Skip to content

Instantly share code, notes, and snippets.

@volost
Created January 31, 2017 13:51
Show Gist options
  • Save volost/21de10a8e6f4dfcdd985dbcda9cc20b5 to your computer and use it in GitHub Desktop.
Save volost/21de10a8e6f4dfcdd985dbcda9cc20b5 to your computer and use it in GitHub Desktop.
Вычисление разницы между двумя датами:
public static void main(String[] args) throws Exception
{
Date currentTime = new Date(); //получаем текущую дату и время
Thread.sleep(3000); //ждём 3 секунды – 3000 миллисекунд
Date newTime = new Date(); //получаем новое текущее время
long msDelay = newTime.getTime() - currentTime.getTime(); //вычисляем разницу
System.out.println("Time distance is: " + msDelay + " in ms");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment