Java Hour Calculate getTime(String dateStr, int hour, String timeZone)

Here you can find the source of getTime(String dateStr, int hour, String timeZone)

Description

get Time

License

Open Source License

Declaration

public static long getTime(String dateStr, int hour, String timeZone) 

Method Source Code

//package com.java2s;
/**/* w w w .j av a  2  s  .co m*/
 * Copyright (c) 2014 Xiufeng Liu ( xiufeng.liu@uwaterloo.ca )
 * <p/>
 * This file is free software: you may copy, redistribute and/or modify it
 * under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 * <p/>
 * This file 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.
 * <p/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static long getTime(String dateStr, int hour, String timeZone) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        try {
            simpleDateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
            Date date = simpleDateFormat.parse(dateStr + " " + hour
                    + ":00:00");
            return date.getTime();
        } catch (ParseException ex) {
            System.out.println("Exception " + ex);
        }
        return 0L;
    }

    public static long getTime(String timestamp, String timeZone) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        try {
            simpleDateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
            Date date = simpleDateFormat.parse(timestamp);
            return date.getTime();
        } catch (ParseException ex) {
            System.out.println("Exception " + ex);
        }
        return 0L;
    }
}

Related

  1. getDelayTime(int hour, String date)
  2. getDiffDateTime(int diff, int hours)
  3. getDiffHour(String startTime, String endTime)
  4. getDoubleValue(String hours)
  5. getExpiresDate(int hours)
  6. getTimestampFromDateHour2(String d)
  7. getTimeStringOfHourBefore(int hour)
  8. getTomorrowSixHours()
  9. getWeeHours()