Here you can find the source of formatDate(String date, int format)
Parameter | Description |
---|---|
date | the date string |
format | the date format |
public static String formatDate(String date, int format)
//package com.java2s; /******************************************************************************* * Copyright (c) 2005-2012 Synopsys, Incorporated * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w . ja va 2 s. c o m*/ * Synopsys, Inc - Initial implementation *******************************************************************************/ public class Main { private static String[] months = new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; /** * Reads a particular date format then translates it to another format. The only format implemented so far is * "MM-DD-YYYY" which can have anything as a delimiter. It also parses based on the delimiter, so it can really be * M-D-YY even. * @param date the date string * @param format the date format * @return the translated string */ public static String formatDate(String date, int format) { String retVal = null; if (date == null || date.length() == 0) return "unknown"; String[] strs = date.split("-"); if (strs.length != 3) return "unknown"; int month = Integer.parseInt(strs[0]); int day = Integer.parseInt(strs[1]); int year = Integer.parseInt(strs[2]); retVal = months[month - 1] + " " + day + ", " + year; return retVal; } }