Java Date Start getStringDate()

Here you can find the source of getStringDate()

Description

get String Date

License

Open Source License

Declaration

public static String getStringDate() 

Method Source Code

//package com.java2s;
/**//w  w w .  j  a  v  a 2 s. c om
 * OpenCPS is the open source Core Public Services software
 * Copyright (C) 2016-present OpenCPS community
    
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
    
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 */

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static String getStringDate() {

        Calendar calendar = Calendar.getInstance();

        StringBuffer sb = new StringBuffer();

        int month = calendar.get(Calendar.MONTH) + 1;

        int day = calendar.get(Calendar.DAY_OF_MONTH);

        sb.append(calendar.get(Calendar.YEAR));

        if (month < 10) {
            sb.append(0);
            sb.append(month);
        } else {
            sb.append(month);
        }

        if (day < 10) {
            sb.append(0);
            sb.append(day);
        } else {
            sb.append(day);
        }

        return sb.toString();
    }

    public static Calendar getInstance(Date date, int... ignores) {

        Calendar calendar = Calendar.getInstance();
        if (ignores != null && ignores.length > 0) {
            for (int f = 0; f < ignores.length; f++) {
                calendar.set(ignores[f], 0);
            }
        }
        return calendar;
    }
}

Related

  1. getStartTimeByManDay(Date serviceStartTime)
  2. getStartTimeOfDate(Date date)
  3. getStartTimeOfDay(Date date)
  4. getStartTimeOfDay(Date date)
  5. getStrDateToDate(String dateStr)
  6. getStringDate(byte[] block, int pos)
  7. getStringInDate(String dateString)