Java Utililty Methods Calendar to String

List of utility methods to do Calendar to String

Description

The list of methods to do Calendar to String are organized into topic(s).

Method

StringcalendarToString(Calendar cal)
net.ajaskey.market.ta.printCalendar
String ret = cal.toString() + "\n";
ret += "  Year         : " + cal.get(Calendar.YEAR) + "\n";
ret += "  Month        : " + cal.get(Calendar.MONTH) + "\n";
ret += "  Day of Month : " + cal.get(Calendar.DAY_OF_MONTH) + "\n";
ret += "  Day of Year  : " + cal.get(Calendar.DAY_OF_YEAR) + "\n";
ret += "  Week of Year : " + cal.get(Calendar.WEEK_OF_YEAR) + "\n";
return ret;
StringcalendarToString(Calendar cal, String format)
calendar To String
StringBuffer sb = new StringBuffer();
if (cal == null) {
    return "";
if (format.indexOf("yyyy/") != -1) {
    sb.append(cal.get(Calendar.YEAR));
    sb.append("/");
if (format.indexOf("MM/") != -1) {
    sb.append(cal.get(Calendar.MONTH) + 1);
    sb.append("/");
if (format.indexOf("dd") != -1) {
    sb.append(cal.get(Calendar.DATE));
    sb.append(" ");
if (format.indexOf("hh") != -1) {
    if (format.indexOf("hh:") != -1) {
        sb.append(cal.get(Calendar.HOUR_OF_DAY));
        sb.append(":");
    } else {
        sb.append(cal.get(Calendar.HOUR_OF_DAY));
if (format.indexOf("mm") != -1) {
    if (format.indexOf("mm:") != -1) {
        sb.append(cal.get(Calendar.MINUTE));
        sb.append(":");
    } else {
        sb.append(cal.get(Calendar.MINUTE));
if (format.indexOf("ss") != -1) {
    sb.append(cal.get(Calendar.SECOND));
return sb.toString();
StringcalendarToString(Calendar calendar)
calendar To String
return (new SimpleDateFormat(FORMAT_PATTERN, LOCAL_ES)).format(calendar.getTime());
StringcalendarToString(Calendar calendar)
Converts the calender to a string.
String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
String[] days = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
if (calendar == null) {
    return "Thu Jan 01 00:00:00 UTC 1970";
int dow = calendar.get(Calendar.DAY_OF_WEEK);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
...
StringcalendarToString(Calendar calendar)
Convert a Gregorian calendar object to string representation
if (calendar == null) {
    return "";
return fmt.format(calendar.getTime());
StringcalendarToString(Calendar calendar, String template)
calendar To String
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}",
...
StringcalendarToString(Calendar date, boolean transformToLocalTime)
calendar To String
int clientZoneOffset = 7200000; 
int clientDSTOffset = 3600000; 
String stringDate = "";
if (!transformToLocalTime) {
    stringDate = appendZero(date.get(Calendar.DATE)) + "." + appendZero(date.get(Calendar.MONTH) + 1) + "."
            + date.get(Calendar.YEAR);
    stringDate += " " + appendZero(date.get(Calendar.HOUR_OF_DAY)) + ":"
            + appendZero(date.get(Calendar.MINUTE)) + ":" + appendZero(date.get(Calendar.SECOND));
...
StringCalendarToString(Calendar fecha, String formato)
Calendar To String
if (nullToBlank(fecha).equals("")) {
    return "";
SimpleDateFormat df = new SimpleDateFormat(formato);
return df.format(fecha.getTime());
StringcalendarToXSDString(Calendar cal, String fmt)
calendar To XSD String
SimpleDateFormat dFmt = new SimpleDateFormat(fmt);
Date date = cal.getTime();
String lex = dFmt.format(date);
lex = lex + calcTimezone(cal);
return lex;
CalendardateToCalendar(final String date)
date To Calendar
assert date != null : "'date' can't be null";
assert date.length() != 0 : "'date' can't be empty";
Calendar cal = Calendar.getInstance();
try {
    cal.setTime((Date) new SimpleDateFormat(DATE_FORMAT).parse(date));
} catch (ParseException e) {
return cal;
...