Java Timestamp Create toTimeStamp(String sDate, String format)

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

Description

to Time Stamp

License

Open Source License

Declaration

public static Timestamp toTimeStamp(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 Timestamp toTimeStamp(String sDate) {
        return toTimeStamp(sDate, "dd/MM/yyyy");
    }/* w ww .j  a v a 2 s .c o m*/

    public static Timestamp toTimeStamp(String sDate, String format) {
        Timestamp timeStampDate = null;
        Date utilDate = null;
        if (sDate != null) {
            utilDate = toUtilDate(sDate, format);
            timeStampDate = toTimeStamp(utilDate);
        }
        return timeStampDate;
    }

    public static Timestamp toTimeStamp(Date utilDate) {
        Timestamp timeStampDate = null;
        if (utilDate != null) {
            timeStampDate = new Timestamp(utilDate.getTime());
        }
        return timeStampDate;
    }

    public static Timestamp toTimeStamp(java.sql.Date sqlDate) {
        Timestamp timeStampDate = null;
        if (sqlDate != null) {
            timeStampDate = new Timestamp(sqlDate.getTime());
        }
        return timeStampDate;
    }

    public static Date toUtilDate(String sDate) {
        return toUtilDate(sDate, "dd/MM/yyyy");
    }

    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. toTimestamp(String _sDate)
  2. toTimestamp(String dateTime)
  3. toTimestamp(String dateTime)
  4. toTimestamp(String dt)
  5. toTimestamp(String s)
  6. toTimestamp(String str, String format)
  7. toTimestamp(String value)
  8. toTimestamp(String yyyymmddhhmmss)
  9. toTimestamp2(long seconds, int fraction, int width)