Java Date to String DateToString(Date date, String parttern)

Here you can find the source of DateToString(Date date, String parttern)

Description

Date To String

License

Open Source License

Declaration

public static String DateToString(Date date, String parttern) 

Method Source Code

//package com.java2s;
/**/*from   ww w. j  a va  2s .  co m*/
 * ============================================================================== Copyright (c) 2015 by www.tencent.com,
 * All rights reserved. ============================================================================== This software is
 * the confidential and proprietary information of tencent.com, Inc. ("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 tencent.com, Inc.
 * ------------------------------------------------------------------------------
 * <p/>
 * Author: faberxu Date: 2015/12/18 Description: Nothing. Function List: 1. Nothing. History: 1. Nothing.
 * ==============================================================================
 */

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String DateToString(Date date, String parttern) {
        String dateString = null;
        if (date != null) {
            try {
                dateString = getDateFormat(parttern).format(date);
            } catch (Exception e) {
            }
        }
        return dateString;
    }

    private static SimpleDateFormat getDateFormat(String parttern) throws RuntimeException {
        return new SimpleDateFormat(parttern);
    }
}

Related

  1. dateToString(Date date, String format)
  2. dateToString(Date date, String format)
  3. dateToString(Date date, String format)
  4. dateToString(Date date, String format)
  5. dateToString(Date date, String formatStr)
  6. dateToString(Date date, String pattern)
  7. DateToString(Date date, String pattern)
  8. dateToString(Date date, String pattern)
  9. dateToString(Date date, String pattern)