Here you can find the source of convertDate(String inPattern, String outPattern, String date)
Parameter | Description |
---|---|
inPattern | The SimpleDateFormat pattern to use for parsing the inbound date string (e.g. "yyyyMMddHHmmss"). |
outPattern | The SimpleDateFormat pattern to use for formatting the outbound date string (e.g. "yyyyMMddHHmmss"). |
date | The date string to convert. |
Parameter | Description |
---|---|
Exception | an exception |
public static String convertDate(String inPattern, String outPattern, String date) throws Exception
//package com.java2s; /*//from www .j a va 2 s.c o m * Copyright (c) Mirth Corporation. All rights reserved. * * http://www.mirthcorp.com * * The software in this package is published under the terms of the MPL license a copy of which has * been included with this distribution in the LICENSE.txt file. */ import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * Parses a date string according to a specified input pattern, and formats the date back to a * string according to a specified output pattern. * * @param inPattern * The SimpleDateFormat pattern to use for parsing the inbound date string (e.g. * "yyyyMMddHHmmss"). * @param outPattern * The SimpleDateFormat pattern to use for formatting the outbound date string (e.g. * "yyyyMMddHHmmss"). * @param date * The date string to convert. * @return The converted date string. * @throws Exception */ public static String convertDate(String inPattern, String outPattern, String date) throws Exception { Date newDate = getDate(inPattern, date); return formatDate(outPattern, newDate); } /** * Parses a date string according to the specified pattern and returns a java.util.Date object. * * @param pattern * The SimpleDateFormat pattern to use (e.g. "yyyyMMddHHmmss"). * @param date * The date string to parse. * @return A java.util.Date object representing the parsed date. * @throws Exception */ public static Date getDate(String pattern, String date) throws Exception { SimpleDateFormat formatter = new SimpleDateFormat(pattern); return formatter.parse(date); } /** * Formats a java.util.Date object into a string according to a specified pattern. * * @param pattern * The SimpleDateFormat pattern to use (e.g. "yyyyMMddHHmmss"). * @param date * The java.util.Date object to format. * @return The formatted date string. */ public static String formatDate(String pattern, Date date) { SimpleDateFormat formatter = new SimpleDateFormat(pattern); return formatter.format(date); } }