Java Date Format Check checkTimestamp(String timestamp)

Here you can find the source of checkTimestamp(String timestamp)

Description

check Timestamp

License

Open Source License

Declaration

public static boolean checkTimestamp(String timestamp) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Date;
import java.util.concurrent.TimeUnit;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {
    public static boolean checkTimestamp(String timestamp) {

        SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        Date time = null;/*from  w ww.  ja va2 s .  co m*/
        try {
            time = dateFormat.parse(timestamp);
        } catch (ParseException e) {
            System.out.println("Timestamp check error");
            e.printStackTrace();
            System.exit(-1);
        }
        Date current = new Date();

        long diffInMillies = current.getTime() - time.getTime();
        TimeUnit timeUnit = TimeUnit.MINUTES;
        long diff = timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS);

        if (diff < 60)
            return true;

        return false;
    }
}

Related

  1. checkDateFormatAndValite(String strDateTime, String format)
  2. checkDateInToday(Date date)
  3. checkDateRange(String fromDate, String endDate)
  4. checkDateValidity(String str, String formatString)
  5. checkTime(int id)