Skip to content

Instantly share code, notes, and snippets.

@puma007
Forked from fankay/DateUtil.java
Created August 27, 2013 14:19
Show Gist options
  • Save puma007/6354118 to your computer and use it in GitHub Desktop.
Save puma007/6354118 to your computer and use it in GitHub Desktop.
package com.kaishengit.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtil {
public static String getNiceDate(String dateString) {
String result = dateString;
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date date = df.parse(dateString);
long time = System.currentTimeMillis() - date.getTime();
time = time / 1000;
if(time < 10) {
result = "刚刚";
} else if(time >= 10 && time < 60) {
result = "一分钟之内";
} else if(time >= 60 && time < 3600) {
result = "一小时之内";
} else if(time >= 3600 && time < 86400) {
result = "今天";
}
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
System.out.println(getNiceDate("2012-08-06 18:25:34"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment