Java yyyy formatDate(Date date, String format)

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

Description

format Date

License

Apache License

Declaration

public static String formatDate(Date date, String format) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {

    public static String formatDate(Date date, String format) {
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        System.out.println(formatter.format(date).toString());
        return formatter.format(date).toString();

    }/*from  www . ja v  a2s.  c o m*/

    public static String formatDate(String date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        SimpleDateFormat sdf2 = new SimpleDateFormat(format);
        String sss = null;
        try {
            sss = sdf2.format(sdf.parse(date));
            //System.out.println(sss);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return sss;
    }

    public static String formatDate(long date) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(formatter.format(date));
        return formatter.format(date);
    }
}

Related

  1. formatBySlashForm(Date aDate)
  2. formatDate(Calendar cal, String pattern)
  3. formatDate(Calendar calendar, String format)
  4. formatDate(Date date, String datePattern)
  5. formatDate(Date date, String format)
  6. formatDate(Date date, String outputPattern)
  7. formatDate(Date date, String pattern)
  8. formatDate(Date date, String pattern)
  9. formatDate(Date date, String pattern)