Java Year Month getTimeByYearMonth(String yearMonth, String timeZone)

Here you can find the source of getTimeByYearMonth(String yearMonth, String timeZone)

Description

get Time By Year Month

License

Open Source License

Declaration

public static long getTimeByYearMonth(String yearMonth, String timeZone) 

Method Source Code

//package com.java2s;
/**//from w  ww .j  a va2s.  com
 * 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 getTimeByYearMonth(String yearMonth, String timeZone) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        try {
            simpleDateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
            Date date = simpleDateFormat.parse(yearMonth + "-01 00:00:00");
            return date.getTime();
        } catch (ParseException ex) {
            System.out.println("Exception " + ex);
        }
        return 0L;
    }

    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. getQuarterToYearMonthDay(Integer year, Integer quarter)
  2. getStartMonth(int year, int month)
  3. getTheLastDayOfTheMonth(int year, int month)
  4. getThisYearMonth()
  5. getThisYearMonth()
  6. getYearAndMonth()
  7. getYearMonth()
  8. getYearMonth()
  9. getYearMonth(Calendar sDate)