Java String to Date toDateString(Date date, String format)

Here you can find the source of toDateString(Date date, String format)

Description

to Date String

License

Apache License

Declaration

public static String toDateString(Date date, String format) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

    public static String toDateString(Date date, String format) {
        SimpleDateFormat sf = new SimpleDateFormat(format);
        return sf.format(date);
    }// www  .  j  a va 2 s  . co  m

    public static String format(String text, Date date) {
        int start = text.indexOf("{");
        int end = text.indexOf("}");
        while (start > 0 && end > 0) {
            String subStr = text.substring(start, end + 1);
            String format = text.substring(start + 1, end);
            String dateStr = toDateString(date, format);
            text = text.replace(subStr, dateStr);

            start = text.indexOf("{");
            end = text.indexOf("}");
        }
        return text;
    }
}

Related

  1. toDateString(Date date)
  2. toDateString(Date date)
  3. toDateString(Date date)
  4. toDateString(Date date, String format)
  5. toDateString(Date date, String format)
  6. toDateString(Date date, String formatPattern)
  7. toDateString(Date date, TimeZone timezone)
  8. toDateString(final Date date)
  9. toDateString(java.util.Date date)