Here you can find the source of dateToStringWithPattern(Date date, String pattern)
Parameter | Description |
---|---|
date | the specified date to convert |
pattern | time format |
public static String dateToStringWithPattern(Date date, String pattern)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**//ww w . j a va 2 s. com * return time value of specified date * * @param date * the specified date to convert * @param pattern * time format * @return String value */ public static String dateToStringWithPattern(Date date, String pattern) { try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); return simpleDateFormat.format(date); } catch (Exception e) { return ""; } } }