Java Timestamp Parse parseDateTimeToTimestamp(String string)

Here you can find the source of parseDateTimeToTimestamp(String string)

Description

yyyy-MM-dd HH:mm:ss

License

Apache License

Parameter

Parameter Description
string a parameter

Declaration

public static Timestamp parseDateTimeToTimestamp(String string) 

Method Source Code


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

import java.sql.Timestamp;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {
    /**/*  w w  w . j a  va 2 s .c  o  m*/
     * yyyy-MM-dd HH:mm:ss Comment for <code>allDateFmt</code>
     */
    public static final SimpleDateFormat allDateFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);

    /**
     * yyyy-MM-dd HH:mm:ss
     * 
     * @param string
     * @return
     */
    public static Timestamp parseDateTimeToTimestamp(String string) {
        Timestamp result = null;
        try {
            Date date = allDateFmt.parse(string);

            result = new Timestamp(date.getTime());
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return result;
    }
}

Related

  1. parse(java.sql.Timestamp timestamp)
  2. parseAsCassandraTimestamp(String dateString)
  3. parseHeaderDate(String timestamp)
  4. parseSnapshotTimestamp(final String tstamp)
  5. parseSQLiteTimestamp(String dd)
  6. parseStopTime(String timestamp, String timezone)