Java Date to String dateToString(String str, DateTimeFormatter dateTimeFormatter)

Here you can find the source of dateToString(String str, DateTimeFormatter dateTimeFormatter)

Description

date To String

License

Apache License

Declaration

public static String dateToString(String str, DateTimeFormatter dateTimeFormatter) 

Method Source Code


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

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

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;

public class Main {
    private static final DateTimeFormatter fmt = ISODateTimeFormat.dateTime();

    public static String dateToString(String str, DateTimeFormatter dateTimeFormatter) {
        DateTime dt = dateTimeFormatter.parseDateTime(str);
        return dt.toString(fmt);
    }/*from w ww  . j  a  v  a  2 s .c  o m*/

    public static String parseDateTime(String dateTimeString, String[] validFormats, String outputFormat) {
        for (int i = 0; i < validFormats.length; i++) {
            SimpleDateFormat format = new SimpleDateFormat(validFormats[i]);
            DateFormat df = new SimpleDateFormat(outputFormat);
            format.setLenient(false);
            try {
                Date temp = format.parse(dateTimeString);
                if (temp != null) {
                    return df.format(temp);
                }
            } catch (ParseException e) {
            }
        }
        return null;
    }
}

Related

  1. DateToString(Date thisdate, Locale locale)
  2. dateToString(final Date date)
  3. dateToString(final Date value, final boolean utc)
  4. dateToString(java.util.Date currdate, String strFormat)
  5. dateToString(String date, String format)
  6. dateToString1(Date date, String formatIn)
  7. dateToString_yyyyMMddHHmmssSSS(Date date)
  8. DateToStringByformat2(Date date)
  9. dateToStringFecha(Date fecha)