Java Hour Format formatDate(String dateTimeString)

Here you can find the source of formatDate(String dateTimeString)

Description

Extracts date and month from dateTimeString and formats

License

Apache License

Parameter

Parameter Description
dateTimeString in format 2012-10-15T08:17:00

Return

format dd/MM

Declaration

public static String formatDate(String dateTimeString) 

Method Source Code

//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 {
    /**/* ww  w.  j  a va 2s  .c o  m*/
     *Extracts date and month from dateTimeString and formats 
     * @param dateTimeString in format 2012-10-15T08:17:00
     * @return format dd/MM
     * */
    public static String formatDate(String dateTimeString) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd'T'HH:mm:ss");
        Date date = null;
        try {
            date = dateFormat.parse(dateTimeString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        String day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
        String month = String.valueOf(cal.get(Calendar.MONTH) + 1);
        return day + "/" + month;
    }
}

Related

  1. formatDate(java.util.Date date, String pattern)
  2. formatDate(java.util.Date dtFormat, String sFormatString)
  3. formatDate(Object obj, String format)
  4. formatDate(String date)
  5. formatDate(String date)
  6. formatDate(String format)
  7. formatDate(String inputStr)
  8. formatDate(String pattern, Date date)
  9. formatDate2DateTimeStr()