Last active
November 14, 2015 20:04
-
-
Save agtokty/ae16c44f69adcc7509c1 to your computer and use it in GitHub Desktop.
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.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
public class Main { | |
public static void main(String[] args) { | |
SimpleDateFormat format = new SimpleDateFormat("dd MM yy HH:mm"); | |
String dateStart = "10 11 2015 21:00"; | |
Date start = null; | |
try { | |
start = format.parse(dateStart); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
System.out.println(getDiff(start)); | |
} | |
public static String getDiff(Date _date){ | |
Date _now = new Date(); | |
long diff = _now.getTime() - _date.getTime(); | |
int diffMinutes = (int)diff / (60 * 1000); | |
String mesaj = ""; | |
if(diffMinutes < 60) | |
mesaj = diffMinutes + " dakika önce"; | |
else if(60 <= diffMinutes && diffMinutes < 60*24) | |
mesaj = diffMinutes/60 + " saat önce"; | |
else if(60*24 <= diffMinutes && diffMinutes < 30*60*24) | |
mesaj = diffMinutes/(60*24) + " gun önce"; | |
else | |
mesaj = "yıllaar önce"; | |
return mesaj; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment