Java Timestamp Format toTimeStamp(String dateTime, SimpleDateFormat format, int timeZoneOffset)

Here you can find the source of toTimeStamp(String dateTime, SimpleDateFormat format, int timeZoneOffset)

Description

Convert a string to a time stamp using the same algorithm as the Aerospike loader.

License

Apache License

Declaration

public static long toTimeStamp(String dateTime, SimpleDateFormat format, int timeZoneOffset)
        throws ParseException 

Method Source Code

//package com.java2s;
/*//  www .j  a  v a2 s . c om
 * Copyright 2012-2015 Aerospike, Inc.
 *
 * Portions may be licensed to Aerospike, Inc. under one or more contributor
 * license agreements WHICH ARE COMPATIBLE WITH THE APACHE LICENSE, VERSION 2.0.
 *
 * Licensed 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.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    /**
     * Convert a string to a time stamp using the same algorithm as the Aerospike loader.
     */
    public static long toTimeStamp(String dateTime, SimpleDateFormat format, int timeZoneOffset)
            throws ParseException {
        Date formatDate = format.parse(dateTime);
        long miliSecondForDate = formatDate.getTime() - timeZoneOffset;
        return miliSecondForDate / 1000;
    }

    /**
     * Convert a string to a time stamp using a string pattern.
     */
    public static long toTimeStamp(String dateTime, String pattern, int timeZoneOffset) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        return toTimeStamp(dateTime, format, timeZoneOffset);
    }
}

Related

  1. timestampToString(Long timestamp, String formatStr)
  2. timeToString(long timestamp, SimpleDateFormat format)
  3. toDateFromTimestamp(String timestamp, String format)
  4. toHumanTime(long timestamp, String format)
  5. toReadableTime(Long timestamp, String format)
  6. unixTimestamp(String date, String dateFormat)