Java Date Now getCurrentDate(final String FORMAT)

Here you can find the source of getCurrentDate(final String FORMAT)

Description

This method returns current date in specific format given

License

Open Source License

Parameter

Parameter Description
FORMAT a parameter

Return

current date in given format

Declaration

public static String getCurrentDate(final String FORMAT) 

Method Source Code

//package com.java2s;
/**//from  w  w  w.  j a va  2s  .c o  m
 * Created on Aug 9, 2004
 *
 * Copyright 2005 by Arysys Technologies (P) Ltd.,
 * #3,Shop line,
 * Sasmira Marg,
 * Worli,Mumbai 400 025
 * India
 *
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Arysys Technologies (P) Ltd. ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Arysys Technologies (P) Ltd.
 *
 */

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

public class Main {
    /**
     * This method returns current date in specific format given
     * @author Rahul Kubadia
     * @since 4.1
     * @date 08-Feb-2012
     * @param FORMAT
     * @return current date in given format
     */
    public static String getCurrentDate(final String FORMAT) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(FORMAT);
            Calendar c = Calendar.getInstance();
            return sdf.format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public static String getCurrentDate() {
        String s = "";
        Format formatter;
        Date rightNow = new Date();
        formatter = new SimpleDateFormat("EEEE , dd MMM yyyy");
        s = formatter.format(rightNow);
        return s;
    }

    public static long getTime(String dateTimeString) {
        long time = 0;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = sdf.parse(dateTimeString);
            time = date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
            time = 0;
        }
        return time;
    }
}

Related

  1. getCurrentDate()
  2. getCurrentDate()
  3. getCurrentDate(boolean WithDelimeter)
  4. getCurrentDate(Date date)
  5. getCurrentDate(final String form)
  6. getCurrentDate(String format)
  7. getCurrentDate(String format)
  8. getCurrentDate(String format)
  9. getCurrentDate(String format)