Java Timestamp to String timestampToString(Timestamp ts)

Here you can find the source of timestampToString(Timestamp ts)

Description

Conversion setting to 0 the nanoseconds, to deal with the mysql driver bug affecting the reverse translation (see stringToTimestamp()).

License

Open Source License

Parameter

Parameter Description
ts timestamp

Return

the string

Declaration

public static String timestampToString(Timestamp ts) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012-2015 INRIA.//from w  w  w  . j a  v a2s .  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 the mysql driver bug affecting
     * the reverse translation (see stringToTimestamp()).
     * 
     * @param ts timestamp
     * @return the string 
     */
    public static String timestampToString(Timestamp ts) {
        ts.setNanos(0);
        return ts.toString();
    }
}

Related

  1. timestampToString(Timestamp now, String pattern)
  2. timeStampToString(Timestamp stamp, String dateTimeFormat, TimeZone tz, Locale locale)
  3. timestampToString(Timestamp timestamp)
  4. timestampToString(Timestamp timestamp)
  5. timestampToString(Timestamp timestamp, String pattern)
  6. timestampToString(Timestamp ts, Calendar cal)
  7. timestampToStringFF(Timestamp date)
  8. timestampToUTC(Timestamp marcTimestamp)
  9. toString(Timestamp t, String precision)