Java Date ISO Parse iso8601ToDate(String s)

Here you can find the source of iso8601ToDate(String s)

Description

iso To Date

License

Apache License

Declaration

private static synchronized Date iso8601ToDate(String s) throws ParseException 

Method Source Code


//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

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

import java.util.Date;

public class Main {
    private static final SimpleDateFormat ISO8601_DATE_FORMAT_MILLIS = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    private static final SimpleDateFormat ISO8601_DATE_FORMAT_SECS = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ss'Z'");
    private static final SimpleDateFormat ISO8601_DATE_FORMAT_MINS = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
    private static final SimpleDateFormat ISO8601_DATE_FORMAT_DATE = new SimpleDateFormat("yyyy-MM-dd");

    private static synchronized Date iso8601ToDate(String s) throws ParseException {
        Date d = null;/*from  w ww . j a va 2 s.co  m*/
        try {
            d = ISO8601_DATE_FORMAT_MILLIS.parse(s);
        } catch (ParseException e1) {
            try {
                d = ISO8601_DATE_FORMAT_SECS.parse(s);
            } catch (ParseException e2) {
                try {
                    d = ISO8601_DATE_FORMAT_MINS.parse(s);
                } catch (ParseException e3) {
                    d = ISO8601_DATE_FORMAT_DATE.parse(s);
                }
            }
        }
        return d;
    }
}

Related

  1. getIsoStringDate(Date date)
  2. getISOStringFromDate(long time)
  3. iso8601(String date)
  4. iso86012date(String s)
  5. iso8601ToCalendar(String s)
  6. ISO8601ToSeconds(String iso8601)
  7. isoDateStringToDate(String dateString)
  8. isOneOf(String value, String... values)
  9. ISOToJulianDate(String dateObs)