Java SQL Date Get getDateFromISODateString(String isoDate)

Here you can find the source of getDateFromISODateString(String isoDate)

Description

get Date From ISO Date String

License

Open Source License

Declaration

public static Date getDateFromISODateString(String isoDate) 

Method Source Code

//package com.java2s;
/*//  ww w . j  a  v  a 2 s .co m
 * @(#)ConversionUtil.java
 *
 * Copyright by ObjectFrontier, Inc.,
 * 12225 Broadleaf Lane, Alpharetta, GA 30005, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of ObjectFrontier, Inc. 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 ObjectFrontier.
 */

import java.sql.Date;

public class Main {
    public static Date getDateFromISODateString(String isoDate) {

        String year = getCurrentYear();

        return getDateFromRTGSDateString(year + isoDate);
    }

    /**
     * This method should return the current year 
     *  
     * @return string
     */
    public static String getCurrentYear() {

        java.sql.Date date = new java.sql.Date(System.currentTimeMillis());

        java.text.SimpleDateFormat out = new java.text.SimpleDateFormat("yyyymmdd");

        return out.format(date).substring(0, 4);
    }

    public static Date getDateFromRTGSDateString(String iobDate) {

        Date date = null;
        try {
            int year = Integer.parseInt(iobDate.substring(0, 4));
            int month = Integer.parseInt(iobDate.substring(4, 6));
            int day = Integer.parseInt(iobDate.substring(6, 8));
            date = new Date(year - 1900, month - 1, day);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return date;
    }
}

Related

  1. getDateByNum(String dateNum)
  2. getDateByYearAndMonth(int year, int month)
  3. getDateDiscrepancy(String startDate, String endDate)
  4. getDateEnd(Date date)
  5. getDateForStr(String str)
  6. getDateFromLong(ResultSet resultSet, int index)
  7. getDateFromResultSet(ResultSet rset, Enum field)
  8. getDateFromRTGSDateString(String iobDate)
  9. getDateFromTimestamp(Timestamp timestamp)