Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Calendar;

public class Main {
    /**
     * Returns two days old date from the current date. This is used with forusquare web service to get the data
     * according to date.
     * 
     * @return date in string.
     */
    public static String getTwoDaysOldDate() {

        int yyyy = Calendar.getInstance().get(Calendar.YEAR);
        int MM = Calendar.getInstance().get(Calendar.MONTH) + 1;
        int dd = Calendar.getInstance().get(Calendar.DATE) - 2;
        Calendar cal = Calendar.getInstance();
        if (dd < 1) {
            MM = MM - 1;
            if (MM < 0) {
                MM = 0;
            }
        }

        if (MM < 0) {
            yyyy = yyyy - 1;
        }
        cal.set(yyyy, MM, 1);
        dd = cal.getActualMaximum(Calendar.DATE) - dd;
        String oldDate = String.format("%04d%02d%02d", yyyy, MM, dd);

        return oldDate;
    }
}