Java Date Format ISO getISO8601FormatDate(String in)

Here you can find the source of getISO8601FormatDate(String in)

Description

get ISO Format Date

License

Open Source License

Declaration

public static final Date getISO8601FormatDate(String in) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Main {
    private static Lock lock = new ReentrantLock();

    public static final Date getISO8601FormatDate(String in) {
        lock.lock();//from  ww  w  .  ja va 2  s  .  com
        try {
            try {
                return getDateFormat().parse(in);
            } catch (ParseException e) {
                throw new RuntimeException("Date failed to parse as ISO 8601: " + in);
            }
        } finally {
            lock.unlock();
        }
    }

    /**
     * Returns a formatter for ISO 8601 format as described at http://www.cl.cam.ac.uk/~mgk25/iso-time.html
     * @return
     */
    public static final DateFormat getDateFormat() {
        lock.lock();
        try {
            TimeZone tz = TimeZone.getTimeZone("UTC");
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
            df.setTimeZone(tz);
            return df;
        } finally {
            lock.unlock();
        }
    }
}

Related

  1. getIso8601DateFormat()
  2. getISO8601DateFormat(TimeZone tz, String mask)
  3. getISO8601DateString(Date d)
  4. getIso8601DateString(long timestampWithMilliseconds)
  5. getIso8601DayDateFormat()
  6. getIso8601String(Date d)
  7. getISO8601String(Date date)
  8. getISO8601String(Date date)
  9. getISO8601Time()