Java Timestamp Format formatDateToTimestamp(String string)

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

Description

yyyy-MM-dd

License

Apache License

Parameter

Parameter Description
string a parameter

Declaration

public static Timestamp formatDateToTimestamp(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 {
    /**//from  ww  w.j ava2s  . com
     * yyyy-MM-dd Comment for <code>onlyDateFmt</code>
     */
    public static final SimpleDateFormat onlyDateFmt = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);

    /**
     * yyyy-MM-dd
     * 
     * @param string
     * @return
     */
    public static Timestamp formatDateToTimestamp(String string) {
        Timestamp result = null;
        try {
            Date date = onlyDateFmt.parse(string);

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

Related

  1. formatDateTime(java.sql.Timestamp ts)
  2. formatDateTime(long ms)
  3. formatDateTime(String dTime)
  4. formatDateTime(Timestamp t, String pattern)
  5. formatDateTimeStamp(final Date date)
  6. formatDateToUnixTimestamp(Date date)
  7. formatDateWithCinderellaTime(Date date)
  8. formatDefaultDate(Timestamp time)
  9. formatDuration(final long duration)