Java Date Now currentDate()

Here you can find the source of currentDate()

Description

Formats the current date.

License

Open Source License

Return

- the string representation of the current date.

Declaration

public static String currentDate() 

Method Source Code

//package com.java2s;
/*/*from w w w  .j av a  2  s  .c  o m*/
 * Icegem, Extensions library for VMWare vFabric GemFire
 * 
 * Copyright (c) 2010-2011, Grid Dynamics Consulting Services Inc. or third-party  
 * contributors as indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  
 * 
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License v3, as published by the Free Software Foundation.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * You should have received a copy of the GNU Lesser General Public License v3
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /** */
    private static final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

    /**
     * Formats the current date.
     * 
     * @return - the string representation of the current date.
     */
    public static String currentDate() {
        return dateToString(System.currentTimeMillis());
    }

    /**
     * Formats date to string.
     * 
     * @param date
     *            - the date.
     * @return - the string representation of the Date object.
     */
    public static String dateToString(Date date) {
        return formatter.format(date);
    }

    /**
     * Formats millisecond time to string.
     * 
     * @param date
     *            - the date in milliseconds.
     * @return - the string representation of the date in milliseconds.
     */
    public static String dateToString(long date) {
        return dateToString(new Date(date));
    }
}

Related

  1. currentDate()
  2. currentDate()
  3. currentDate()
  4. currentDate()
  5. currentDate()
  6. currentDate()
  7. currentDate()
  8. currentDate(int dateStyle)
  9. currentDate(String format)