Java Parse Date parseDate(Date date)

Here you can find the source of parseDate(Date date)

Description

Parses a date and returns a formated date string in the form: "yyyy-MM-dd HH:mm:ss z", where z is the time zone.

License

Open Source License

Parameter

Parameter Description
date The date that needs to be converted into a formated string.

Return

String A formated date string.

Declaration

public static String parseDate(Date date) 

Method Source Code


//package com.java2s;
/*//from   w w  w.ja  v a 2 s .c  om
* Copyright (c) 2013, California Institute of Technology
* ALL RIGHTS RESERVED.
* Based on Government Sponsored Research DE-SC0007346
* Author Michael Bredel <michael.bredel@cern.ch>
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
*     http://www.apache.org/licenses/LICENSE-2.0
* 
* 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
* HOLDER 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.
* 
* Neither the name of the California Institute of Technology
* (Caltech) nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*/

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

public class Main {
    /**
     * Parses a date and returns a formated date string in the
     * form: "yyyy-MM-dd HH:mm:ss z", where z is the time zone.
     * 
     * @param timestamp The unix timestamp that needs to be converted into a formated string.
     * @return <b>String</b> A formated date string.
     */
    public static String parseDate(long timestamp) {
        Date date = new Date();
        date.setTime(timestamp);
        return parseDate(date);
    }

    /**
     * Parses a date and returns a formated date string in the
     * form: "yyyy-MM-dd HH:mm:ss z", where z is the time zone.
     * 
     * @param date The date that needs to be converted into a formated string.
     * @return <b>String</b> A formated date string.
     */
    public static String parseDate(Date date) {
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
        return dateformat.format(date);
    }
}

Related

  1. parseDate(@Nonnull final String sFormat, @Nonnull final String sValue)
  2. parseDate(@Nonnull String stringDate)
  3. parseDate(@Nullable String value)
  4. parseDate(Date date)
  5. parseDate(Date date)
  6. parseDate(Date date)
  7. parseDate(Date date)
  8. parseDate(Date date)
  9. parseDate(Date date, int style, Locale local, boolean withTime)