Here you can find the source of getTimestampAtMidnightForDaysAgo(int days)
public static Timestamp getTimestampAtMidnightForDaysAgo(int days)
//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()); } }