Java Timestamp Parse stringToTimestamp(String ts)

Here you can find the source of stringToTimestamp(String ts)

Description

Conversion setting to 0 the nanoseconds, to deal with a mysql driver bug: nanoseconds value is not correct.

License

Open Source License

Parameter

Parameter Description
ts the string

Return

the timestamp

Declaration

public static Timestamp stringToTimestamp(String ts) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012-2015 INRIA.//from w  w w. java2 s.  c om
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Generoso Pagano - initial API and implementation
 ******************************************************************************/

import java.sql.Timestamp;

public class Main {
    /**
     * Conversion setting to 0 the nanoseconds,
     * to deal with a mysql driver bug:
     * nanoseconds value is not correct.
     * e.g. if the string does not contains nanoseconds
     * a non deterministic value is used for nanoseconds.
     * 
     * @param ts the string
     * @return the timestamp
     */
    public static Timestamp stringToTimestamp(String ts) {
        Timestamp t = Timestamp.valueOf(ts);
        t.setNanos(0);
        return t;
    }
}

Related

  1. stringToTimestamp(String aS_Timestamp, String aS_Format, Timestamp aTs_ValidStart, Timestamp aTs_ValidEnd)
  2. stringToTimestamp(String date, String formatStr)
  3. stringToTimeStamp(String dateTimeString, String dateTimeFormat, TimeZone tz, Locale locale)
  4. stringToTimestamp(String marcTimestamp)
  5. stringToTimestamp(String sTimestamp)
  6. stringToTimestamp(String value)
  7. stringToTimesTamp(String yMd, boolean isEndTime)
  8. stripToMinutes(java.sql.Timestamp timestamp)