Android SQL Date Format DateToString(Date date, String separador)

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

Description

Date To String

Declaration

public static String DateToString(Date date, String separador) 

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  ww .  j a v a  2 s  .  co 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)
  2. formatDate(java.sql.Date value, String defaultFormat)
  3. formatDate(java.util.Date value)
  4. formatDate(java.util.Date value, String defaultFormat)
  5. DateToStringSQL(Date date, String separador)
  6. DateToString(Date date)
  7. date2String(java.sql.Date date)