Java SQL Date to Util Date toUtilDate(String sDate, String format)

Here you can find the source of toUtilDate(String sDate, String format)

Description

to Util Date

License

Open Source License

Declaration

public static Date toUtilDate(String sDate, String format) 

Method Source Code


//package com.java2s;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    public static Date toUtilDate(String sDate) {
        return toUtilDate(sDate, "dd/MM/yyyy");
    }//from   www .  j  a  v a 2 s  . co m

    public static Date toUtilDate(String sDate, String format) {
        Date utilDate = null;
        try {
            SimpleDateFormat tempDate = new SimpleDateFormat(format);
            utilDate = tempDate.parse(sDate);
        } catch (ParseException e) {
            System.out.println("Found error exception while toUtilDate.\n" + e);
        }
        return utilDate;
    }

    public static Date toUtilDate(java.sql.Date sqlDate) {
        Date utilDate = null;
        utilDate = (Date) sqlDate;
        return utilDate;
    }

    public static Date toUtilDate(Timestamp timeStampDate) {
        Date utilDate = null;
        GregorianCalendar gc = new GregorianCalendar(timeStampDate.getYear(), timeStampDate.getMonth(),
                timeStampDate.getDate());
        utilDate = gc.getTime();
        return utilDate;
    }
}

Related

  1. toUtilDate(Date date)
  2. toUtilDate(java.sql.Date d)
  3. toUtilDate(java.sql.Date date)
  4. toUtilDateFromSqlDate(java.sql.Date p_sqlDate)