Skip to main content

Posts

Showing posts from October, 2015

Date Utility Class in Java

/**
 * Date Util might be useful in your daily activities.
 */
package com.sbs.dateutil;

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

/**
 * @author bhargav
 *
 */
public class DateUtil {

    /**
     *
     */
    private DateUtil() {

    }

    /**
     * @param args
     */
    public static void main(String[] args) {

        //Date date = new Date();
        //Another way to get the current date from Calender object is
        Date utilDate = Calendar.getInstance().getTime();

        System.out.println("Default Util Curent Date and time :" + utilDate);
        SimpleDateFormat DATE_FORMAT = null;

        DATE_FORMAT = new SimpleDateFormat("dd-MM-YYYY");
        System.out.println("dd-MM-YYYY Formatted Date " + DATE_FORMAT.format(utilDate));

        DATE_FORMAT = new SimpleDateFormat("dd-MM-YY");
        System.out.println("dd-MM-YY Formatted Date " + DATE_FORMAT.format(utilDate));

          …