Java SimpleDateFormat get Today's date

Description

Java SimpleDateFormat get Today's date


import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static void main(String[] argv) throws Exception {
        long time = 2;
        System.out.println(isToday(time));
    }/*from w ww.  java  2 s  . c om*/

    public static boolean isToday(long time) {
        long now = System.currentTimeMillis();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String today = formatter.format(new Date(now));
        String timeday = formatter.format(new Date(time));
        if (timeday.equals(today)) {
            return true;
        }
        return false;
    }
}



PreviousNext

Related