Here you can find the source of getBeginEndDayOfMonth(String yearMonthString)
Parameter | Description |
---|---|
yearMonthString | a parameter |
public static Date[] getBeginEndDayOfMonth(String yearMonthString)
//package com.java2s; /**// w ww. j av a 2 s . c om * Project: CarTracServer * * File Created at Apr 6, 2013 * $id$ * * Copyright 2013, Shawn Chain (shawn.chain@gmail.com). * All rights reserved. * * 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.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { /** * Get the begin/end day of a month * @param yearMonthString * @return an Date array with begin date at 0 and end date at 1 or null if any error occured */ public static Date[] getBeginEndDayOfMonth(String yearMonthString) { try { Date begin, end; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); begin = sdf.parse(yearMonthString); Calendar cal = getCalendar(); cal.setTime(begin); cal.add(Calendar.MONTH, 1); cal.add(Calendar.MILLISECOND, -1); end = cal.getTime(); return new Date[] { begin, end }; } catch (Exception e) { // NOOP } return null; } public static Calendar getCalendar() { return Calendar.getInstance(TimeZone.getTimeZone("GMT+8")); } }