Java tutorial
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static boolean showMessageTime(String currentTime, String prevTime) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date currentDate = sdf.parse(currentTime); Date prevDate = sdf.parse(prevTime); if (currentDate.getTime() - prevDate.getTime() >= 300000) { return true; } } catch (Exception e) { e.printStackTrace(); } return false; } public static String getTime(long time) { SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd HH:mm"); return format.format(new Date(time)); } public static String getTime() { SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); return format.format(new Date()); } }