Java Date Before getDateBefore(int offsetDay, String strFormat)

Here you can find the source of getDateBefore(int offsetDay, String strFormat)

Description

get Date Before

License

Open Source License

Declaration

public static String getDateBefore(int offsetDay, String strFormat) 

Method Source Code

//package com.java2s;
/**/*  w  w w.  j  a v  a2s.co m*/
 * ============================================================================== Copyright (c) 2015 by www.tencent.com,
 * All rights reserved. ============================================================================== This software is
 * the confidential and proprietary information of tencent.com, Inc. ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in accordance with the terms of the license agreement
 * you entered into with tencent.com, Inc.
 * ------------------------------------------------------------------------------
 * <p/>
 * Author: faberxu Date: 2015/12/18 Description: Nothing. Function List: 1. Nothing. History: 1. Nothing.
 * ==============================================================================
 */

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

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

    public static String getDateBefore(int offsetDay, String strFormat) {
        String strDay = "";
        long nNow = getTimestamp();
        long mydate = nNow - (long) offsetDay * 24 * 3600 * 1000;
        SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
        strDay = sdf.format(new Date(mydate));
        return strDay;
    }

    public static long getTimestamp() {
        Date dateNow = new Date();
        return dateNow.getTime();
    }
}

Related

  1. getBeforeHourByCurrentTime(Date now, int mount)
  2. getBeforeOrAfterDateByDayNumber(int dayNumber)
  3. getDateBefore(Date d, int day)
  4. getDateBefore(Date d, int day)
  5. getDateBefore(Date date, int days)
  6. getDateBefore(int year, int month, int day)
  7. getDateBefore(String d, int day)
  8. getDateBeforeHours(Date date, int hours)
  9. getDateBeforeNextMonth(Date date, Integer month, Integer day)