Java Date Parse getDateFromIRODSValue(final String irodsValue)

Here you can find the source of getDateFromIRODSValue(final String irodsValue)

Description

Utility to return an irods date value as a java.util.Date

License

BSD License

Parameter

Parameter Description
irodsValue <code>String</code> containing an IRODS date value as returned from a query to ICAT

Return

java.util.Date reflecting the IRODS time, or null if no date in the data

Declaration

public static Date getDateFromIRODSValue(final String irodsValue) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    /**/*from  w w w. ja v  a 2  s . c  o  m*/
     * Utility to return an irods date value as a <code>java.util.Date</code>
     *
     * @param irodsValue
     *            <code>String</code> containing an IRODS date value as returned
     *            from a query to ICAT
     * @return <code>java.util.Date</code> reflecting the IRODS time, or
     *         <code>null</code> if no date in the data
     */
    public static Date getDateFromIRODSValue(final String irodsValue) {

        if (irodsValue == null) {
            throw new IllegalArgumentException("null date value");
        }

        if (irodsValue.isEmpty()) {
            return null;
        }

        Integer dateInteger;

        try {
            dateInteger = Integer.parseInt(irodsValue);
        } catch (NumberFormatException nfe) {
            throw new IllegalArgumentException(
                    "malformed date value, cannot translate to integer:"
                            + irodsValue);
        }

        TimeZone timeZone = TimeZone.getTimeZone("GMT");
        DateFormat dateFormat = DateFormat.getDateTimeInstance();
        dateFormat.setTimeZone(timeZone);
        Calendar calendar = Calendar.getInstance();

        calendar.setTimeInMillis(0L);
        calendar.add(Calendar.SECOND, dateInteger.intValue());
        Date computedDate = calendar.getTime();
        return computedDate;
    }
}

Related

  1. getDateFromDCItemTimestamp(String dateTimeStamp)
  2. getDateFromFileName(String fileName)
  3. getDateFromFormat(Date date, String type)
  4. getDateFromFormattedDate(String dateStr, String format)
  5. getDateFromFormattedTimeStamp( String formattedTimeStamp)
  6. getDateFromISO8601(Object iso8601)
  7. getDateFromISO8601(String dateString)
  8. getDateFromISO8601(String iso8601Date)
  9. getDateFromIsoString(String dateString)