Java Timestamp from convertToTimestampHMS(String dateData)

Here you can find the source of convertToTimestampHMS(String dateData)

Description

convert To Timestamp HMS

License

Open Source License

Declaration

public static Timestamp convertToTimestampHMS(String dateData) 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;

import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {

    public static Timestamp convertToTimestampHMS(String dateData) {

        if (dateData == null)
            return null;
        if (dateData.trim().equals(""))
            return null;

        String yearString = dateData.substring(0, 4);
        String monthString = dateData.substring(4, 6);
        String dayString = dateData.substring(6, 8);
        String hourString = dateData.substring(8, 10);
        String minString = dateData.substring(10, 12);
        String secString = dateData.substring(12, 14);

        int year = Integer.parseInt(yearString);
        int month = Integer.parseInt(monthString) - 1;
        int day = Integer.parseInt(dayString);
        int hour = Integer.parseInt(hourString);
        int min = Integer.parseInt(minString);
        int sec = Integer.parseInt(secString);

        Calendar cal = new GregorianCalendar();
        cal.set(year, month, day, hour, min, sec);

        return new Timestamp(cal.getTime().getTime());
    }//from ww  w .j  a v a  2 s  . c o  m
}

Related

  1. convertToTimestamp(String dateData)
  2. convertToTimestamp(String dateString, String pattern)
  3. convertToTimestamp(String s)
  4. convertToTimeStamp(Timestamp timestamp, String format, TimeZone timeZone)
  5. convertToTimestampDate(Date date)
  6. getFirstTimeOfDay(Calendar calendar)
  7. timestampFromCalendar(Calendar calendar)
  8. timestampFromLong(long t)
  9. timestampFromYearMonthDateHourMinuteSecondNanos( int year, int month, int date, int hour, int minute, int second, int nanos)