頁面停留時間

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.hadoop.hive.ql.exec.UDF;

public class rz extends UDF {


	private String uid = "";


	private Date lastTime = null;
	
	public Long evaluate(String currentTime, String currentUid) throws ParseException {
		this.uid = currentUid;
		SimpleDateFormat sf = new SimpleDateFormat("yyyy/M/d HH:mm");
		Date current = sf.parse(currentTime);
		if (lastTime == null) {
			lastTime = current;
			return 0L;
		} else {
			
			if (this.uid.equals(currentUid)) {
				Long useTime = lastTime.getTime() - current.getTime();
				lastTime = current;
				return useTime;
			} else { 
				return 0L;
			}
		}
		
	}
}

發佈了38 篇原創文章 · 獲贊 0 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章