Skip to content

Instantly share code, notes, and snippets.

@NaniteFactory
Created October 21, 2017 06:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NaniteFactory/4229d0435dca8206fa84ae46bcf6e43d to your computer and use it in GitHub Desktop.
Save NaniteFactory/4229d0435dca8206fa84ae46bcf6e43d to your computer and use it in GitHub Desktop.
Calculating seconds between two Dates within Java. 자바에서 두 날짜 값의 차이를 초로 구하기.
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.Date;
import java.text.ParseException;
public class Main {
public static void main(String[] args) throws ParseException {
// TODO Auto-generated method stub
SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss", Locale.KOREA);
Date d1 = f.parse("01:05:10");
Date d2 = f.parse("01:05:07");
long diff = d1.getTime() - d2.getTime();
long sec = diff / 1000;
System.out.println(sec);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment