Java Timestamp Convert To timestampToLong(Timestamp ts)

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

Description

Convert a timestamp to seconds.

License

Open Source License

Parameter

Parameter Description
ts Timestamp in any timezone.

Return

Seconds since epoch with timezone ignored.

Declaration

static long timestampToLong(Timestamp ts) 

Method Source Code

//package com.java2s;
/* -*- mode: java; c-basic-offset: 4; indent-tabs-mode: nil; -*-
 *  vim:expandtab:shiftwidth=4:tabstop=4:smarttab:
 *
 *  ndb-bindings: Bindings for the NDB API
 *  Copyright (C) 2008 MySQL/* w  w w .ja v  a  2 s  . c  o m*/
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.sql.Timestamp;

public class Main {
    /**
     * Convert a timestamp to seconds. The timezone is ignored and the current
     * date and time are taken to be relative to GMT. For example if
     * <code>2007-01-01 13:00:00 CDT</code> (CDT = GMT-5:00), we convert this
     * into seconds as if calling getTime() on <code>2007-01-01 13:00:00 GMT</code>.
     *
     * @param ts Timestamp in any timezone.
     * @return Seconds since epoch with timezone ignored.
     */
    static long timestampToLong(Timestamp ts) {
        /* It's easier to use getTime() and reverse instead of just ignore it. */
        return (ts.getTime() / 1000) - (ts.getTimezoneOffset() * 60);
    }
}

Related

  1. timestampToDate(Timestamp tt)
  2. TimestampToDateStr(Timestamp tmp)
  3. timestampToDateString(Timestamp ts)
  4. timestampToDayNumber(long timestamp)
  5. timestampToInternal(java.sql.Timestamp ts)
  6. timestampToMicros(Timestamp timestamp)
  7. timestampToParts(long time)
  8. timestampToPrettyString(long ts)
  9. timestampToSearchString(final Timestamp timestamp)