Here you can find the source of getFirstDayInThisQuarter(String nowDate)
@SuppressWarnings("deprecation") public static String getFirstDayInThisQuarter(String nowDate)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { @SuppressWarnings("deprecation") public static String getFirstDayInThisQuarter(String nowDate) { String ntime = ""; int nowMonth; int nowYear; try {//from w w w . ja v a 2 s . c o m SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date startDate = df.parse(nowDate); nowMonth = startDate.getMonth() + 1; nowYear = startDate.getYear() + 1900; while (true) { if (nowMonth >= 10) { ntime = nowYear + "-10-01"; break; } if (nowMonth >= 7) { ntime = nowYear + "-07-01"; break; } if (nowMonth >= 4) { ntime = nowYear + "-04-01"; break; } if (nowMonth >= 1) { ntime = nowYear + "-01-01"; break; } } } catch (Exception e) { //System.out.println(e); } return ntime; } public static String getYear() { return getDateString("yyyy"); } public static String getDateString() { return getDateString("yyyy-MM-dd"); } public static String getDateString(int after) { return addDay(getDateString("yyyy-MM-dd"), after); } public static String getDateString(String format) { SimpleDateFormat df = new SimpleDateFormat(format); Date date = new Date(System.currentTimeMillis()); String dateStr = df.format(date); return dateStr; } public static String addDay(String beginDateStr, int adddaycount) { java.text.SimpleDateFormat format = new java.text.SimpleDateFormat( "yyyy-MM-dd"); try { Date beginDate = format.parse(beginDateStr); Calendar cal = Calendar.getInstance(); cal.setTime(beginDate); cal.add(Calendar.DATE, adddaycount); Date enddate = cal.getTime(); return format.format(enddate); } catch (ParseException e) { e.printStackTrace(); } return null; } public static Date addDay(Date beginDate, int addcount) { Calendar cal = Calendar.getInstance(); cal.setTime(beginDate); cal.add(Calendar.DAY_OF_YEAR, addcount); Date enddate = cal.getTime(); return enddate; } }