Here you can find the source of dateToString(String str, DateTimeFormatter dateTimeFormatter)
public static String dateToString(String str, DateTimeFormatter dateTimeFormatter)
//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; } }