Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    public static String getNowTime(int i) {
        SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd");
        Date beginDate = new Date();
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        date.set(Calendar.DATE, date.get(Calendar.DATE) - i);
        Date endDate = null;
        try {
            endDate = dft.parse(dft.format(date.getTime()));
            String format = dft.format(endDate);
            return format;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }
}