Java Date Now getCurrentDate()

Here you can find the source of getCurrentDate()

Description

get Current Date

License

Apache License

Declaration

public static String getCurrentDate() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {

    public static String getCurrentDate() {
        Calendar date1 = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date1.getTime());
    }//from   w  w  w . ja v  a2 s  .c  o  m

    public static String getCurrentDate(boolean bool) {
        Calendar date1 = Calendar.getInstance();
        if (bool) {
            date1.add(Calendar.DATE, -1);
        } else {
            date1.add(Calendar.DATE, 1);
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date1.getTime());
    }

    public static String getCurrentDate(boolean bool, String currentDate) {
        Calendar date1 = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = sdf.parse(currentDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        date1.setTime(date);

        if (bool) {
            date1.add(Calendar.DATE, -1);
        } else {
            date1.add(Calendar.DATE, 1);
        }

        return sdf.format(date1.getTime());
    }
}

Related

  1. getCurrentDate()
  2. getCurrentDate()
  3. getCurrentDate()
  4. getCurrentDate()
  5. getCurrentDate()
  6. getCurrentDate()
  7. getCurrentDate()
  8. getCurrentDate()
  9. GetCurrentDate()