Java Date ISO Parse getCalendarFromISO8601String(final String timestamp, final TimeZone tz)

Here you can find the source of getCalendarFromISO8601String(final String timestamp, final TimeZone tz)

Description

Convert from a ISO8601 style date (YYYY-MM-DDThh:mm:ssZ) string to a Calendar Object.

License

Apache License

Parameter

Parameter Description
timestamp a parameter

Declaration

public static Calendar getCalendarFromISO8601String(final String timestamp, final TimeZone tz) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import java.util.TimeZone;

public class Main {
    /**//  w w  w. j  a v a 2s  .c  o  m
     * Convert from a ISO8601 style date (YYYY-MM-DDThh:mm:ssZ) string to a
     * Calendar Object.
     * 
     * @param timestamp
     * @return
     */
    public static Calendar getCalendarFromISO8601String(final String timestamp, final TimeZone tz) {
        final Calendar cal = Calendar.getInstance(tz);
        final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        try {
            cal.setTime(df.parse(timestamp));
        } catch (final ParseException pe) {
            pe.printStackTrace();
            return null;
        }
        return cal;
    }
}

Related

  1. getADTimeFromISO8601Date(String date)
  2. getISODate(String date)
  3. getISODateInSeconds(String isoDate)
  4. getIsoStringDate(Date date)
  5. getISOStringFromDate(long time)