Android SQL Date Create nowAsDate()

Here you can find the source of nowAsDate()

Description

now As Date

Declaration

public static java.sql.Date nowAsDate() 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {
    public static java.sql.Date nowAsDate() {
        Calendar objCurrentCalendar = Calendar.getInstance();
        StringBuffer sbDateString = new StringBuffer();
        int iYear = objCurrentCalendar.get(Calendar.YEAR);
        int iMonth = objCurrentCalendar.get(Calendar.MONTH) + 1;
        int iDate = objCurrentCalendar.get(Calendar.DATE);
        sbDateString.append(iYear);//from  www  .j  a v a2s  .co  m
        sbDateString.append("-");
        sbDateString.append(iMonth);
        sbDateString.append("-");
        sbDateString.append(iDate);
        try {
            return java.sql.Date.valueOf(sbDateString.toString());
        } catch (Exception e) {
            return new java.sql.Date(System.currentTimeMillis());
        }
    }
}