<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8" %> <% request.setCharacterEncoding("UTF-8"); String t = request.getParameter("t"); %> <%=t%> <%! public String timeDiff(long msec1, long msec2) { long timediff = java.lang.Math.abs(msec1 - msec2); timediff = (long)(timediff/1000); int weeks = (int)java.lang.Math.floor(timediff / (60 * 60 * 24 * 7)); timediff -= weeks * (60 * 60 * 24 * 7); int days = (int)java.lang.Math.floor(timediff / (60 * 60 * 24)); timediff -= days * (60 * 60 * 24); int hours = (int)java.lang.Math.floor(timediff / (60 * 60)); timediff -= hours * (60 * 60); int mins = (int)java.lang.Math.floor(timediff / (60)); timediff -= mins * (60); int secs = (int)timediff; String ans =""; if (weeks!=0) ans+=weeks+" week"+plural(weeks)+" "; if (days!=0) ans+=days+" day"+plural(days)+" "; if (hours!=0) ans+=hours+" hour"+plural(hours)+" "; else { if (mins!=0) ans+=mins+" min"+plural(mins)+" "; else ans += secs +" secs "; } if (hours!=0 && mins!=0) ans="more than "+ans; return ans; } public String plural(int h) { if (h==1) return ""; else return "s"; } public String dateDiff(long msec1, long msec2) { return timeDiff(msec1, msec2)+" ago"; } %>