Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.text.SimpleDateFormat;

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

public class Main {
    /**
     * Format calendar to string
     * @param c Calendar to convert
     * @param format String format of SimpleDateFormat
     * @return String converted
     */
    public static String formatDate(Calendar c, String format) {
        if (c == null) {
            c = Calendar.getInstance();
            c.setTimeInMillis(0);
            c.set(Calendar.YEAR, 1990);
        }

        return formatDate(c.getTime(), format);
    }

    /**
     * Format calendar to string
     * @param date Date to convert
     * @param format String format of SimpleDateFormat
     * @return String converted
     */
    public static String formatDate(Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        if (date == null) {
            date = new Date(0);
        }
        return sdf.format(date);
    }
}