Java tutorial
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String formatDate(String strDate) { try { // create SimpleDateFormat object with source string date format SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // parse the string into Date object Date date = sdfSource.parse(strDate); Date now = new Date(); SimpleDateFormat sdfDestination; if (date.getYear() == now.getYear()) sdfDestination = new SimpleDateFormat("dd MMM"); else sdfDestination = new SimpleDateFormat("dd/MM/yyyy"); return "Added on: " + sdfDestination.format(date); } catch (ParseException pe) { return ""; } } }