Java tutorial
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Locale; public class Main { private static String formatPeriodDate(int daysPeriod) { Calendar now = Calendar.getInstance(); Calendar period = Calendar.getInstance(); period.add(Calendar.DAY_OF_MONTH, daysPeriod); SimpleDateFormat sdf = new SimpleDateFormat("MMMM", Locale.US); if (now.get(Calendar.YEAR) == period.get(Calendar.YEAR)) { if (now.get(Calendar.MONTH) == period.get(Calendar.MONTH)) { return period.get(Calendar.DAY_OF_MONTH) + "-" + now.get(Calendar.DAY_OF_MONTH) + " " + sdf.format(now.getTime()) + ", " + now.get(Calendar.YEAR); } return period.get(Calendar.DAY_OF_MONTH) + " " + sdf.format(period.getTime()) + " - " + now.get(Calendar.DAY_OF_MONTH) + " " + sdf.format(now.getTime()) + ", " + now.get(Calendar.YEAR); } return period.get(Calendar.DAY_OF_MONTH) + " " + sdf.format(period.getTime()) + " " + period.get(Calendar.YEAR) + " - " + now.get(Calendar.DAY_OF_MONTH) + " " + sdf.format(now.getTime()) + " " + now.get(Calendar.YEAR); } }