Java Parse Date parseDate(String str, String timezone)

Here you can find the source of parseDate(String str, String timezone)

Description

parse Date

License

Open Source License

Declaration

public static final Date parseDate(String str, String timezone) 

Method Source Code


//package com.java2s;
/*/*  w w  w. j av  a  2s . c om*/
 * ====================================================================
 * Copyright (c) 2004 TMate Software Ltd.  All rights reserved.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at http://tmate.org/svn/license.html.
 * If newer versions of this license are posted there, you may use a
 * newer version instead, at your option.
 * ====================================================================
 */

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    private static final DateFormat ISO8601_FORMAT_IN = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");

    public static final Date parseDate(String str, String timezone) {
        if (timezone != null) {
            ISO8601_FORMAT_IN.setTimeZone(TimeZone.getTimeZone(timezone));
        }
        if (str == null) {
            return new Date(0);
        }
        try {
            return ISO8601_FORMAT_IN.parse(str);
        } catch (Throwable e) {
        }
        return new Date(0);
    }
}

Related

  1. parseDate(String str)
  2. parseDate(String str, boolean strict, String... parsePatterns)
  3. parseDate(String str, DateFormat df)
  4. parseDate(String str, Locale locale, String... parsePatterns)
  5. parseDate(String str, String pattern)
  6. parseDate(String str, String[] parsePatterns)
  7. parseDate(String str, String[] parsePatterns)
  8. parseDate(String strDate)
  9. parseDate(String strDate)