页面停留时间

时间:2021-12-25 17:19:39
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;
			}
		}
		
	}
}