Here you can find the source of checkDateRange(String fromDate, String endDate)
Parameter | Description |
---|---|
fromDate | the from date |
endDate | the end date |
public static boolean checkDateRange(String fromDate, String endDate)
//package com.java2s; /**// w ww.j av a 2 s . com * Copyright (c) 2014 Far Eastone Telecommunications Co., Ltd. * All Rights Reserved. * * This software is the confidential and proprietary information of * Far Eastone Telecommunications Co., Ltd. ("Confidential Information"). * * You shall not disclose such Confidential Information and shall use it * only in accordance with the terms of license agreement you entered * into with Far Eastone Telecommunications Co., Ltd. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { /** * Check between date range. * * @param fromDate the from date * @param endDate the end date * @return true, if successful */ public static boolean checkDateRange(String fromDate, String endDate) { long fromTime = transDate(fromDate, "yyyy-MM-dd").getTime(); long endTime = transDate(endDate, "yyyy-MM-dd").getTime(); long todayTime = transDate(getDate(), "yyyy-MM-dd").getTime(); if (fromTime <= todayTime && todayTime <= endTime) { return true; } return false; } /** * Transform date string to Date object. * * @param date the date * @param date_format the date_format * @return Date */ public static Date transDate(String date, String date_format) { try { Date s_date = new SimpleDateFormat(date_format).parse(date); return s_date; } catch (ParseException e) { // e.printStackTrace(); } return null; } /** * Get current date. * * @return string */ public static String getDate() { return _datetime("yyyy-MM-dd"); } /** * Assign return data format. * * @param format the format * @return string */ private static String _datetime(String format) { return _datetime(format, new Date()); } /** * Assign return data format. * * @param format the format * @param date the date * @return string */ private static String _datetime(String format, Date date) { SimpleDateFormat formater = new SimpleDateFormat(format); return formater.format(date).toString(); } /** * Assign return data format (by Locale). * * @param format the format * @param date the date * @param locale the locale * @return string */ private static String _datetime(String format, Date date, Locale locale) { SimpleDateFormat formater = new SimpleDateFormat(format, locale); return formater.format(date).toString(); } }