Java SQL Date Convert toLong(java.util.Date v)

Here you can find the source of toLong(java.util.Date v)

Description

to Long

License

Apache License

Declaration

public static long toLong(java.util.Date v) 

Method Source Code


//package com.java2s;
/*//  w ww .  jav a  2s. co m
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.   See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.   You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.sql.Timestamp;

import java.util.TimeZone;

public class Main {
    private static final TimeZone LOCAL_TZ = TimeZone.getDefault();

    public static long toLong(java.util.Date v) {
        return toLong(v, LOCAL_TZ);
    }

    /** Converts the Java type used for UDF parameters of SQL TIMESTAMP type
     * ({@link java.sql.Timestamp}) to internal representation (long).
     *
     * <p>Converse of {@link #internalToTimestamp(long)}. */
    public static long toLong(Timestamp v) {
        return toLong(v, LOCAL_TZ);
    }

    public static long toLong(java.util.Date v, TimeZone timeZone) {
        long time = v.getTime();
        return time + (long) timeZone.getOffset(time);
    }
}

Related

  1. toGMT(final Date ts)
  2. toInt(java.util.Date v)
  3. toIntDate(Object object, int iDefault)
  4. toJavaDate(java.sql.Date date)
  5. toJavaDate(java.sql.Date sqlDate)
  6. toName(Date date)
  7. totalUpdateCount(int[] result)
  8. toYMD(Date date, String datePtn)