Java Date Offset getOffsetMins(String strDate, String strDate2)

Here you can find the source of getOffsetMins(String strDate, String strDate2)

Description

get Offset Mins

License

Open Source License

Declaration

public static int getOffsetMins(String strDate, String strDate2) throws Exception 

Method Source Code

//package com.java2s;
/**//w ww  . j a  v a 2 s . c o  m
*    Copyright (C) 2012 Cardinal Info.Tech.Co.,Ltd.
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU Affero General Public License, version 3,
*    as published by the Free Software Foundation.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU Affero General Public License for more details.
*
*    You should have received a copy of the GNU Affero General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static int getOffsetMins(String strDate, String strDate2) throws Exception {
        String pFormat = "yyyy-MM-dd HH:mm";
        SimpleDateFormat fmt = new SimpleDateFormat(pFormat);
        SimpleDateFormat fmt2 = new SimpleDateFormat(pFormat);

        Date paramDate1 = fmt.parse(strDate);
        Date paramDate2 = fmt2.parse(strDate2);

        return getOffsetMins(paramDate1, paramDate2);
    }

    public static int getOffsetMins(Date pDate1, Date pDate2) throws Exception {
        long aa = pDate1.getTime();
        long bb = pDate2.getTime();
        return (int) ((aa - bb) / (1000 * 60));
    }

    public static String getTime() {
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(d);
    }
}

Related

  1. getOffsetDate(String startTime, int field, int offset)
  2. getOffsetDate(String strDate, int offset, String pFormat)
  3. getOffsetDate(String strDate, int offset, String pFormat)
  4. getOffsetDateInFormat(int offsetDay, String pattern)
  5. getOffsetDateToDate(Date pDate, int offset)
  6. getOffsetMonth(Date pDate, int offset, String pFormat)