Java Date String to String adjustDate(String format, String value)

Here you can find the source of adjustDate(String format, String value)

Description

adjust Date

License

Mozilla Public License

Declaration

public final static String adjustDate(String format, String value) throws ParseException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * ***** BEGIN LICENSE BLOCK Version: MPL 1.1
 * /*from w  w w .jav  a2  s .c  o m*/
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * 
 * The Original Code is the OpenCustomer CRM.
 * 
 * The Initial Developer of the Original Code is Thomas Bader (Bader & Jene
 * Software-Ingenieurb?ro). Portions created by the Initial Developer are
 * Copyright (C) 2005 the Initial Developer. All Rights Reserved.
 * 
 * Contributor(s): Thomas Bader <thomas.bader@bader-jene.de>
 * 
 * ***** END LICENSE BLOCK *****
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    public final static String adjustDate(String format, String value) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(format);

        Date date = sdf.parse(value);

        Calendar cal = GregorianCalendar.getInstance();

        cal.setTime(date);
        if (cal.get(Calendar.YEAR) < 100)
            cal.add(Calendar.YEAR, 2000);

        return sdf.format(cal.getTime());
    }
}

Related

  1. dateToDateEN(String in)
  2. dateToFileName(String date)
  3. dateToInt(String date)
  4. dateToString(String date)