Java Date to String date2String(Date date)

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

Description

date String

License

Apache License

Declaration

public static String date2String(Date date) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2015 htd0324@gmail.com//from   www  .j  ava  2s  .  co  m
 * 
 * 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
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.TimeZone;

public class Main {
    public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";

    public static String date2String(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
        formatter.setTimeZone(TimeZone.getDefault());
        return formatter.format(date);
    }

    public static String date2String(Date date, String pattern) {
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        formatter.setTimeZone(TimeZone.getDefault());
        return formatter.format(date);
    }
}

Related

  1. date2Str(final Date date, final String dateFormat)
  2. date2Str(SimpleDateFormat date_sdf)
  3. date2string(Date _aDate)
  4. date2string(Date date)
  5. date2String(Date date)
  6. date2string(Date date)
  7. date2String(Date date)
  8. date2String(Date date)
  9. date2string(Date date)