Java SQL Date Get getDateDiscrepancy(String startDate, String endDate)

Here you can find the source of getDateDiscrepancy(String startDate, String endDate)

Description

get Date Discrepancy

License

Open Source License

Declaration

public static Map<String, Long> getDateDiscrepancy(String startDate, String endDate) 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Main {
    private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static Map<String, Long> getDateDiscrepancy(String startDate, String endDate) {
        try {//from www  .  j av  a  2s  . c  o m
            Map<String, Long> result = new HashMap<String, Long>();
            Date start = dateFormat.parse(startDate);
            Date end = dateFormat.parse(endDate);
            long allsecond = (end.getTime() - start.getTime()) / 1000;
            long day = allsecond / (24 * 3600);
            long hour = allsecond % (24 * 3600) / 3600;
            long minute = allsecond % 3600 / 60;
            long second = allsecond % 60;

            result.put("day", day);
            result.put("hour", hour);
            result.put("minute", minute);
            result.put("second", second);
            return result;
        } catch (ParseException e) {
            return null;
        }
    }

    public static Timestamp getTime() {
        return new Timestamp(new Date().getTime());
    }
}

Related

  1. getDateAsLong(Timestamp date)
  2. getDateBefore(Date date, Integer before)
  3. getDateBeforTwelveMonth()
  4. getDateByNum(String dateNum)
  5. getDateByYearAndMonth(int year, int month)
  6. getDateEnd(Date date)
  7. getDateForStr(String str)
  8. getDateFromISODateString(String isoDate)
  9. getDateFromLong(ResultSet resultSet, int index)