Android SQL Date Format DateToString(Date date)

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

Description

Date To String

Declaration

public static String DateToString(Date date) 

Method Source Code

//package com.java2s;
import java.sql.Date;
import java.util.Calendar;

public class Main {
    public static String DateToString(Date date, String separador) {
        if (date == null) {
            return null;
        }//from w  w w .  j  a  v  a  2s .  c  o  m
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int dia = calendar.get(Calendar.DAY_OF_MONTH);
        String stringDia = dia < 10 ? "0" + dia : String.valueOf(dia);

        int mes = calendar.get(Calendar.MONTH) + 1;
        String stringMes = mes < 10 ? "0" + mes : String.valueOf(mes);

        int ano = calendar.get(Calendar.YEAR);

        String dataEmString = stringDia + separador + stringMes + separador
                + ano;
        return dataEmString;
    }

    public static String DateToString(Date date) {
        return DateToString(date, "-");
    }
}

Related

  1. formatDate(java.sql.Date value, String defaultFormat)
  2. formatDate(java.util.Date value)
  3. formatDate(java.util.Date value, String defaultFormat)
  4. DateToStringSQL(Date date, String separador)
  5. DateToString(Date date, String separador)
  6. date2String(java.sql.Date date)