Android Date Format formatDate(Date time)

Here you can find the source of formatDate(Date time)

Description

Formats date to the string with default time date format.

License

Open Source License

Parameter

Parameter Description
time Date to format.

Return

Result string.

Declaration

public static String formatDate(Date time) 

Method Source Code

//package com.java2s;
/**//from  w w w  . j a v  a2s . c om
 * Copyright ? Microsoft Open Technologies, Inc.
 *
 * All Rights Reserved
 *
 * 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 CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
 * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
 * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
 *
 * See the Apache License, Version 2.0 for the specific language
 * governing permissions and limitations under the License.
 */

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

public class Main {
    /**
     * Default time date format.
     */
    private static final String DEFAULT_TIME_DATE_FORMAT = "yyyy'-'MM'-'dd'T'HH':'mm':'ssZ";

    /**
     * Formats date to the string with default time date format.
     * 
     * @param time Date to format.
     * 
     * @return Result string.
     */
    public static String formatDate(Date time) {
        SimpleDateFormat dateformat = new SimpleDateFormat(
                DEFAULT_TIME_DATE_FORMAT);
        return dateformat.format(time);
    }

    /**
     * Formats date to the string with specific time date format.
     * 
     * @param date Date to format.
     * @param format Format of result string.
     * 
     * @return Formatted date string.
     */
    public static String formatDate(Date date, String format) {
        return new SimpleDateFormat(format).format(date);
    }
}

Related

  1. formatDate(Date date, String pattern)
  2. formatDate(Date date, String pattern)
  3. formatDate(Date date, String pattern)
  4. formatDate(Date date, String pattern)
  5. formatDate(Date date, String pattern, TimeZone zone)
  6. formatDate(SimpleDateFormat s, Date d)
  7. formatDate(String date)
  8. formatDate(long millis)
  9. formatDate1(String date)