Java Timestamp Create getTimestampAtMidnightForDaysAgo(int days)

Here you can find the source of getTimestampAtMidnightForDaysAgo(int days)

Description

get Timestamp At Midnight For Days Ago

License

Mozilla Public License

Declaration

public static Timestamp getTimestampAtMidnightForDaysAgo(int days) 

Method Source Code

//package com.java2s;
/**/*from  ww  w  . j av a2 s .  c  om*/
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations under
 * the License.
 *
 * The Original Code is OpenELIS code.
 *
 * Copyright (C) CIRG, University of Washington, Seattle WA.  All Rights Reserved.
 *
 */

import java.sql.Timestamp;

import java.util.*;

public class Main {
    public static Timestamp getTimestampAtMidnightForDaysAgo(int days) {
        Calendar now = new GregorianCalendar();
        now.add(Calendar.DAY_OF_YEAR, -days);
        now.set(Calendar.HOUR_OF_DAY, 0);
        now.set(Calendar.MINUTE, 0);
        now.set(Calendar.SECOND, 0);
        now.set(Calendar.MILLISECOND, 0);
        return new Timestamp(now.getTimeInMillis());
    }
}

Related

  1. getTimestamp(String strDate)
  2. getTimestamp(String time, String pattern)
  3. getTimestamp2()
  4. getTimeStampAsString(Timestamp formatTime)
  5. getTimestampAsString(Timestamp tsTimestamp)
  6. getTimestampBeforeMs(long someMs)
  7. getTimeStampByFormat(String style)
  8. getTimestampDate(long timestamp)
  9. getTimestampDate(Timestamp ts)