Android examples for java.util:Date Format
Format Date according to Patter of 'YYYY-MM-DD' and Locale of US
/*/* ww w . j a v a 2s .c o m*/ * File: $RCSfile: FormatUtilities.java,v $ * * Copyright (c) 2005 Wincor Nixdorf International GmbH, * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany * All Rights Reserved. * * This software is the confidential and proprietary information * of Wincor Nixdorf ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered * into with Wincor Nixdorf. */ //package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static final String SHORT_DATE_FORMAT = "yyyy-MM-dd"; /** * Format Date according to Patter of 'YYYY-MM-DD' and Locale of US * * @param dat Date to formate * @return Formatted Date */ public static String formatDate(final Date dat) { return formatDate(dat, SHORT_DATE_FORMAT, Locale.US); } /** * Format Date according to Patter and Locale of US * * @param dat Date to format * @param pattern Pattern of Date to format * @return Formatted Date */ public static String formatDate(final Date dat, final String pattern) { return formatDate(dat, pattern, Locale.US); } /** * Format Date according to Pattern and Locale * * @param dat Date to formate * @param pattern Pattern of Date to Format * @param loc Locale of Date to format * @return Formatted Date */ public static String formatDate(final Date dat, final String pattern, final Locale loc) { SimpleDateFormat sdf = new SimpleDateFormat(pattern, loc); if (dat != null) { return sdf.format(dat); } else { return ""; } } }