Java Calendar to String calendarToString(Calendar calendar, String template)

Here you can find the source of calendarToString(Calendar calendar, String template)

Description

calendar To String

License

Open Source License

Declaration

public static String calendarToString(Calendar calendar, String template) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

public class Main {
    public static final String DATE = "yyyy-MM-dd";

    public static String calendarToString(Calendar calendar, String template) {
        String stringCalendar = template;
        stringCalendar = stringCalendar.replace("{year}", String.valueOf(calendar.get(Calendar.YEAR)));
        stringCalendar = stringCalendar.replace("{month}", String.valueOf(calendar.get(Calendar.MONTH)));
        stringCalendar = stringCalendar.replace("{date}", String.valueOf(calendar.get(Calendar.DATE)));
        stringCalendar = stringCalendar.replace("{hour}", String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)));
        stringCalendar = stringCalendar.replace("{minute}", String.valueOf(calendar.get(Calendar.MINUTE)));
        stringCalendar = stringCalendar.replace("{second}", String.valueOf(calendar.get(Calendar.SECOND)));
        stringCalendar = stringCalendar.replace("{millisecond}",
                String.valueOf(calendar.get(Calendar.MILLISECOND)));
        return stringCalendar;
    }//  ww w. j  a va 2s . co m
}

Related

  1. calendarToString(Calendar cal)
  2. calendarToString(Calendar cal, String format)
  3. calendarToString(Calendar calendar)
  4. calendarToString(Calendar calendar)
  5. calendarToString(Calendar calendar)
  6. calendarToString(Calendar date, boolean transformToLocalTime)
  7. CalendarToString(Calendar fecha, String formato)
  8. calendarToXSDString(Calendar cal, String fmt)
  9. dateToCalendar(final String date)