Java Calendar Format format(Calendar calendar, String format)

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

Description

format

License

Open Source License

Declaration

public static String format(Calendar calendar, String format) 

Method Source Code


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

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    private static final String TW = "tw";
    private static final String TWY = "twy";

    public static String format(Calendar calendar, String format) {
        if (format.contains(TWY)) {
            String twy = String.valueOf(calendar.get(Calendar.YEAR) - 1911);
            while (twy.length() < 3) {
                twy = "0" + twy;
            }/*from  w ww .j  a v a2  s .  co m*/
            format = format.replace(TWY, twy);

        } else if (format.contains(TW)) {
            String twy = String.valueOf(calendar.get(Calendar.YEAR) - 1911);
            while (twy.length() < 2) {
                twy = "0" + twy;
            }
            format = format.replace(TW, twy);
        }
        return new SimpleDateFormat(format).format(calendar.getTime());
    }
}

Related

  1. format(Calendar calendar)
  2. format(Calendar calendar)
  3. format(Calendar calendar)
  4. format(Calendar calendar)
  5. format(Calendar calendar)
  6. format(Calendar calendar, String format)
  7. format(Calendar calendar, String formatString)
  8. format(Calendar calendar, String pattern)
  9. format(Calendar current)