convert calendar to date string with format yyyy-MM-dd - Java java.util

Java examples for java.util:Date Format

Description

convert calendar to date string with format yyyy-MM-dd

Demo Code


//package com.java2s;

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

public class Main {
    /**//from   w ww .j  av a  2s. c o m
     * SimpleDateFormat with pattern yyyy-MM-dd
     */
    private static SimpleDateFormat formatYYYY_MM_DD;

    /**
     * convert calendar to date string with format yyyy-MM-dd
     *
     * @param calendar
     * @return
     */
    public static String calendar2Str(Calendar calendar) {
        return formatYYYY_MM_DD.format(calendar.getTime());
    }
}

Related Tutorials