Java Timestamp Create getTimestampAsString(Timestamp tsTimestamp)

Here you can find the source of getTimestampAsString(Timestamp tsTimestamp)

Description

Convert timestamp to string including it's nanosecond portion so that it can be safely stored in variable of web page.

License

Open Source License

Parameter

Parameter Description
tsTimestamp - timestamp to convert

Return

String - text containing time and nanosecond portion of timestamp

Declaration

public static String getTimestampAsString(Timestamp tsTimestamp) 

Method Source Code


//package com.java2s;
/*/*  ww w .j  a  v  a2 s .  c  o  m*/
 * Copyright (C) 2003 - 2013 OpenSubsystems.com/net/org and its owners. All rights reserved.
 * 
 * This file is part of OpenSubsystems.
 *
 * OpenSubsystems is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */

import java.sql.Timestamp;

public class Main {
    /**
     * Separator we used to separate time from the nanosecond portion of the 
     * timestamp when converted to string.
     */
    public static final char NANO_SEPARATOR = ':';

    /**
     * Convert timestamp to string including it's nanosecond portion so that it 
     * can be safely stored in variable of web page.
     * 
     * @param tsTimestamp - timestamp to convert
     * @return String - text containing time and nanosecond portion of timestamp
     */
    public static String getTimestampAsString(Timestamp tsTimestamp) {
        StringBuilder sbTimestamp = new StringBuilder();

        sbTimestamp.append(tsTimestamp.getTime());
        sbTimestamp.append(NANO_SEPARATOR);
        sbTimestamp.append(tsTimestamp.getNanos());

        return sbTimestamp.toString();
    }
}

Related

  1. getTimestamp(String Str)
  2. getTimestamp(String strDate)
  3. getTimestamp(String time, String pattern)
  4. getTimestamp2()
  5. getTimeStampAsString(Timestamp formatTime)
  6. getTimestampAtMidnightForDaysAgo(int days)
  7. getTimestampBeforeMs(long someMs)
  8. getTimeStampByFormat(String style)
  9. getTimestampDate(long timestamp)