Here you can find the source of parseDateTime(String date, String format, String locale, String timeZone)
Parameter | Description |
---|---|
date | the date to parse |
format | the parsing format |
locale | the locale |
timeZone | the timeZone |
public static java.util.Date parseDateTime(String date, String format, String locale, String timeZone)
//package com.java2s; /*//from w w w .ja v a 2 s . c o m * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (http://h2database.com/html/license.html). * Initial Developer: H2 Group * Iso8601: * Initial Developer: Robert Rathsack (firstName dot lastName at gmx dot de) */ import java.text.SimpleDateFormat; import java.util.Locale; import java.util.TimeZone; public class Main { /** * Parses a date using a format string. * * @param date the date to parse * @param format the parsing format * @param locale the locale * @param timeZone the timeZone * @return the parsed date */ public static java.util.Date parseDateTime(String date, String format, String locale, String timeZone) { SimpleDateFormat dateFormat = getDateFormat(format, locale, timeZone); try { synchronized (dateFormat) { return dateFormat.parse(date); } } catch (Exception e) { // ParseException throw new RuntimeException("PARSE_ERROR:" + date, e); } } private static SimpleDateFormat getDateFormat(String format, String locale, String timeZone) { try { // currently, a new instance is create for each call // however, could cache the last few instances SimpleDateFormat df; if (locale == null) { df = new SimpleDateFormat(format); } else { Locale l = new Locale(locale); df = new SimpleDateFormat(format, l); } if (timeZone != null) { df.setTimeZone(TimeZone.getTimeZone(timeZone)); } return df; } catch (Exception e) { throw new RuntimeException("PARSE_ERROR:" + (format + "/" + locale + "/" + timeZone), e); } } }