Here you can find the source of dateToString(Date date, String pattern)
Parameter | Description |
---|---|
date | target date |
pattern | fomate pattern |
public static String dateToString(Date date, String pattern)
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { /**/* w w w . j av a2 s .c o m*/ * Date converted to a string. * * <pre> * DateUtils.dateToString(new Date(0), "yyyyMMdd") --> 19700101 * </pre> * * @param date target date * @param pattern fomate pattern * @return String */ public static String dateToString(Date date, String pattern) { return getDateFormat(pattern).format(date); } /** * return date format with Locale US. * * @param pattern date format pattern. * @return DateFormat */ public static DateFormat getDateFormat(String pattern) { return new SimpleDateFormat(pattern, Locale.US); } }