Java yyyy formatDate(String date)

Here you can find the source of formatDate(String date)

Description

Format date.

License

Open Source License

Parameter

Parameter Description
date the date

Return

the string

Declaration

public static String formatDate(String date) 

Method Source Code


//package com.java2s;

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

public class Main {
    /**/*from  ww w  .  j ava2  s.co  m*/
     * Format date.
     * 
     * @param date
     *            the date
     * @return the string
     */
    public static String formatDate(Date date) {

        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
        return sd.format(date);
    }

    /**
     * Format date.
     * 
     * @param date
     *            the date
     * @return the string
     */
    public static String formatDate(String date) {
        /* Function to change the date format from mm-dd-yy to yy-mm-dd*/
        String invDt1[] = date.toString().split("-");
        String invDt = invDt1[2] + "-" + invDt1[1] + "-" + invDt1[0];
        System.out.println("<<<<date>>>> " + invDt);
        return invDt;
    }
}

Related

  1. formatDate(Date unformattedDate, String format)
  2. formatDate(DateTime aDateTime)
  3. formatDate(final Date date, final String defaultValue)
  4. formatDate(String date)
  5. formatDate(String date)
  6. formatDate(String inputDate)
  7. formatDate2DateStr()
  8. formatDate2DateStr()
  9. formatDate2ShortStr(Date date)