Java Utililty Methods SQL Date

List of utility methods to do SQL Date

Description

The list of methods to do SQL Date are organized into topic(s).

Method

voidcalcLastMonth(String begin, String end, String now, GregorianCalendar calendar)
calc Last Month
calendar.set(calendar.get(GregorianCalendar.YEAR), calendar.get(GregorianCalendar.MONTH), 1);
calendar.add(GregorianCalendar.DATE, -1);
int month = calendar.get(GregorianCalendar.MONTH) - 1;
int d = new Date().getDate();
begin = calendar.get(GregorianCalendar.YEAR) + "-" + month + "-" + d;
System.out.println(" begin: " + begin);
System.out.println(" ---------------------- ");
voidcalcThisMonth(String begin, String end, String now, GregorianCalendar calendar)
calc This Month
end = now;
int dayOfMonth = calendar.get(GregorianCalendar.DATE);
calendar.add(GregorianCalendar.DATE, -dayOfMonth + 1);
begin = new java.sql.Date(calendar.getTime().getTime()).toString();
System.out.println(" begin: " + begin);
System.out.println(" end: " + end);
System.out.println(" ---------------------- ");
booleancanConvert(Class clz)
Returns true if the given class can be converted.
return TRANSFERABLES.contains(clz);
Objectconvert(Class propertyType, Object value, String propertyName)
convert
if (value == null || propertyType.isAssignableFrom(value.getClass())) {
    return value;
if ((byte.class.equals(propertyType) || Byte.class.equals(propertyType)) && value.getClass().isArray()) {
    return value;
} else if (value.getClass().isArray()) {
    Object[] valuesArray = (Object[]) value;
    if (propertyType.isArray()) {
...
Objectconvert(Object o)
convert
if (o == null)
    return o;
if (o instanceof java.sql.Date)
    return new java.util.Date(((java.sql.Date) o).getTime());
return o;
ComparableconvertTo(Class clazz, Object obj)
convert To
if (obj == null) {
    return null;
if (clazz.isAssignableFrom(obj.getClass())) {
    return (Comparable<?>) obj;
if (clazz.isPrimitive()) {
    if (clazz.equals(Long.TYPE)) {
...
ComparableconvertTo(final Class> clazz, Object obj)
convert To
if (obj == null) {
    return null;
if (clazz.isAssignableFrom(obj.getClass())) {
    return (Comparable<?>) obj;
final String oStr = String.valueOf(obj);
if (clazz.equals(String.class)) {
...
List>getClasses()
get Classes
List<Class<?>> toRet = new ArrayList<Class<?>>();
toRet.add(Collection.class);
toRet.add(Comparator.class);
toRet.add(Deque.class);
toRet.add(Enumeration.class);
toRet.add(EventListener.class);
toRet.add(Formattable.class);
toRet.add(Iterator.class);
...
intgetCurrDay()
get Curr Day
Calendar cal = Calendar.getInstance(Locale.CHINA);
cal.setTime(getNowDate());
return cal.get(5);
StringgetCurrentYear()
This method should return the current year
java.sql.Date date = new java.sql.Date(System.currentTimeMillis());
java.text.SimpleDateFormat out = new java.text.SimpleDateFormat("yyyymmdd");
return out.format(date).substring(0, 4);