Here you can find the source of formatDate(java.util.Date d, String format)
Parameter | Description |
---|---|
d | Date object |
format | Date mask, like yyyy-MM-dd or any valid java format |
Parameter | Description |
---|---|
Throwable | an exception |
public static String formatDate(java.util.Date d, String format) throws Throwable
//package com.java2s; /**/*from w w w .jav a2 s. co m*/ * Core-level framework class: String and Date basic utility methods. * <br><br> * Encapsulates utility methods for everyday programming tasks * with Strings, Dates and other common stuff. * <br> * Creation date: 18/09/2003<br> * Last Update: 18/09/2003<br> * (c) 2003 Martin Cordova<br> * This code is released under the LGPL license<br> * @author Martin Cordova (some code written by Carlos Pineda) */ import java.text.SimpleDateFormat; import java.util.Locale; import java.util.Map; public class Main { /** * Format date using a mask and the default locale * @param d Date object * @param format Date mask, like yyyy-MM-dd or any valid java format * @return String representing the formatted string * @throws Throwable */ public static String formatDate(java.util.Date d, String format) throws Throwable { SimpleDateFormat f = new SimpleDateFormat(); f.applyPattern(format); return f.format(d); } /** * Format date using a mask and locale * @param d Date object * @param format Date mask, like yyyy-MM-dd or any valid java format * @param loc Custom Locale * @return String representing the formatted string * @throws Throwable */ public static String formatDate(java.util.Date d, String format, Locale loc) throws Throwable { SimpleDateFormat f = new SimpleDateFormat(format, loc); return f.format(d); } public static String format(String pattern, Map<String, Object> arguments) { String formatedStr = pattern; for (String key : arguments.keySet()) { formatedStr = formatedStr.replaceAll("\\{:" + key + "\\}", arguments.get(key).toString()); } return formatedStr; } }