java 日期差 实现(×分钟前)功能
今天经理让写一个,根据信息上传时间,显示,?分钟前,?小时前,?天前,类似qq空间发表的心情日期;
用了一个自我感觉笨的方法,不过还是实现了,呵呵呵
public static String getCompareTime(String filetime){
//返回的字符串
String retStr ="";
//传入的日期是2008-9-12等,不作处理
if(filetime.indexOf("-")>0){
retStr =filetime;
}
else{
try{
DateFormat day = new SimpleDateFormat("dd");
DateFormat hour = new SimpleDateFormat("HH");
DateFormat minute = new SimpleDateFormat("mm");
Date today = new Date();
//得到当前时间的日,小时,分钟
int nowDay =Integer.parseInt(day.format(today));
int nowHour =Integer.parseInt(hour.format(today));
int nowMinute =Integer.parseInt(minute.format(today));
// System.out.println("nowDay:"+nowDay);
// System.out.println("nowDay:"+nowHour);
// System.out.println("nowDay:"+nowMinute);
//格式化传入的字符串
DateFormat df = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
Date dataTime = df.parse(filetime);
//得到传入时间的日,小时,分钟
int dataDay =Integer.parseInt(day.format(dataTime));
int dataHour =Integer.parseInt(hour.format(dataTime));
&n
相关文档:
先来了解一下链表模式的原理:
首先写一个JavaBean,内容是要添加的元素和该元素的节点。
public class NodeBean implements Serializable
{
private Object data; //元素本身
private NodeBean next; //下一个节点
&n ......
一般,有3种使用锁进行同步的方法
a.方法同步,例如public synchronized void xxx()...
b.静态方法同步,例如public static synchronized void xxx()...
c.程序块同步,例如
...
&n ......
首先看清楚几种常用的字符集编码(java语言是采用unicode字符集编码来表示字符与字符串的):
ASCII(American Standard Code for Information Interchange,美国信息互换标准代码),是基于常用的英文字符的一套电脑编码系统。我们知道英文中经常使用的字符、数字符号被计算机处理时都是以二进制码的形式出现的。这种二进 ......
Java NIO类库Selector机制解析(上)
赵锟 陈皓
http://blog.csdn.net/haoel
一、 前言
自从J2SE 1.4版本以来,JDK发布了全新的I/O类库,简称NIO,其不但引入了全新的高效的I/O机制,同时,也引入了多路复用的异步模式。NIO的包中主要包含了这样几种抽象数据类型:
......
volatile关键字有什么用?
恐怕比较一下volatile和synchronized的不同是最容易解释清楚的。volatile是变量修饰符,而synchronized则作用于一段代码或方法;看如下三句get代码:
int i1; ......