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

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

Description

Date To String SQL

Declaration

public static String DateToStringSQL(Date date, String separador) 

Method Source Code

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

public class Main {
    public static String DateToStringSQL(Date date, String separador) {
        if (date == null) {
            return null;
        }/*from ww w.  j a  v a 2s.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 = ano + separador + stringMes + separador
                + stringDia;
        return dataEmString;
    }
}

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. DateToString(Date date, String separador)
  6. DateToString(Date date)
  7. date2String(java.sql.Date date)