Created
October 21, 2017 06:47
-
-
Save NaniteFactory/4229d0435dca8206fa84ae46bcf6e43d to your computer and use it in GitHub Desktop.
Calculating seconds between two Dates within Java. 자바에서 두 날짜 값의 차이를 초로 구하기.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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