Java Day of stringSomeDaysAgo(Date currentTime, int days)

Here you can find the source of stringSomeDaysAgo(Date currentTime, int days)

Description

string Some Days Ago

License

Apache License

Declaration

public static String stringSomeDaysAgo(Date currentTime, int days) 

Method Source Code

//package com.java2s;
/*//from   w  ww  . j  a  v  a  2  s . c  o m
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    private static final SimpleDateFormat mySdf = new SimpleDateFormat("yyyy-MM-dd");

    public static String stringSomeDaysAgo(Date currentTime, int days) {
        if (currentTime == null)
            return "";
        Calendar cal = Calendar.getInstance();
        cal.setTime(currentTime);
        cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - days);
        return convertDate2String5(cal.getTime());

    }

    public static synchronized String convertDate2String5(Date date) {
        if (date == null) {
            return "";
        }
        //        SimpleDateFormat mySdf = new SimpleDateFormat("yyyy-MM-dd");
        return mySdf.format(date);
    }
}

Related

  1. parseFromDays(String date)
  2. plusDay(Date date, int day)
  3. plusDays(Date date, int days)
  4. setDays(Date date, int amount)
  5. startOfDay(Date date, String format)
  6. strToShortday(String s)
  7. subtractDate(Date d, long day)
  8. toCurrentDatedefer(int day)
  9. ToEnglishDay(Date dt)