Java Timestamp StrToDateTimeFormat(String timestampStr,String pattern)

Here you can find the source of StrToDateTimeFormat(String timestampStr,String pattern)

Description

Str To Date Time Format

License

Apache License

Declaration

public static String StrToDateTimeFormat(String timestampStr,String pattern) throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static String StrToDateTimeFormat(String timestampStr, String pattern) throws ParseException {
        String s = "";
        try {/*from www. j a  v  a  2s  .com*/
            s = String.valueOf(StrToTimestamp(timestampStr, pattern));
            s = s.substring(0, pattern.length());
        } catch (Exception e) {
        }
        return s;
    }

    public static Timestamp StrToTimestamp(String timestampStr, String pattern) throws ParseException {
        java.util.Date date = null;
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        try {
            date = format.parse(timestampStr);
        } catch (ParseException ex) {
            throw ex;
        }
        return date == null ? null : new Timestamp(date.getTime());
    }
}

Related

  1. sqlDate(Timestamp t)
  2. sqlDateConvertoStr(Timestamp date)
  3. sqlDateToCalendar(Timestamp date)
  4. SQLTimestampToDate(java.sql.Timestamp ts)
  5. sqlTimestampToDate(Timestamp t)
  6. strToTimestamp(String date)
  7. strToTimestamp(String dateStr)
  8. strToTimestamp(String i_Today, String i_Hour, String i_Minute)
  9. StrToTimestamp(String timestampStr,String pattern)