Java Parse Date parseDateValue(String value)

Here you can find the source of parseDateValue(String value)

Description

parse Date Value

License

Open Source License

Declaration

public static Date parseDateValue(String value) 

Method Source Code

//package com.java2s;
/**//  w  w  w  .j  a va2s .  c om
 * Logspace
 * Copyright (c) 2015 Indoqa Software Design und Beratung GmbH. All rights reserved.
 * This program and the accompanying materials are made available under the terms of
 * the Eclipse Public License Version 1.0, which accompanies this distribution and
 * is available at http://www.eclipse.org/legal/epl-v10.html.
 */

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.TimeZone;

public class Main {
    private static final String ISO_8601_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
    private static final String TIMEZONE_UTC = "UTC";

    public static Date parseDateValue(String value) {
        try {
            return getTimeFormat().parse(value);
        } catch (ParseException e) {
            throw new IllegalArgumentException("Expected date field of format '" + ISO_8601_DATE_FORMAT
                    + "', but found value '" + value + "'.", e);
        }
    }

    private static DateFormat getTimeFormat() {
        DateFormat df = new SimpleDateFormat(ISO_8601_DATE_FORMAT);
        df.setTimeZone(TimeZone.getTimeZone(TIMEZONE_UTC));
        return df;
    }
}

Related

  1. parseDateToStr(Date date)
  2. parseDateToString(Date date, String format)
  3. parseDateToString(Date date, String pattern)
  4. parseDateToString(Date datetime)
  5. parseDateToString(final Date date, final String dateFormat, final String lang)
  6. parseDateWithFormat(String date, SimpleDateFormat dateFormat, Date defaultDate)
  7. parseDateWithLeniency(final String str, final Locale locale, final String[] parsePatterns, final boolean lenient)
  8. parseDateWithoutTime(final String date)
  9. parseDateWithPattern(Date value, String pattern)