Java Parse Date parseDate(Map obj, String field, String format)

Here you can find the source of parseDate(Map obj, String field, String format)

Description

parse Date

License

Open Source License

Declaration

private static Date parseDate(Map obj, String field, String format) 

Method Source Code


//package com.java2s;
/*/*from   w  w  w  .  ja  va  2 s .  c o m*/
 * Sonar, open source software quality management tool.
 * Copyright (C) 2008-2011 SonarSource
 * mailto:contact AT sonarsource DOT com
 *
 * Sonar is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * Sonar is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sonar; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

public class Main {
    private static Date parseDate(Map obj, String field, String format) {
        String value = getString(obj, field);
        if (value != null) {
            try {
                SimpleDateFormat dateFormat = new SimpleDateFormat(format);
                return dateFormat.parse(value);

            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }
        return null;
    }

    public static String getString(Map obj, String field) {
        Object value = obj.get(field);
        if (value != null) {
            return (String) value;
        }
        return null;
    }
}

Related

  1. parseDate(final String source)
  2. parseDate(final String str)
  3. parseDate(final String str, final Locale locale, final String... parsePatterns)
  4. parseDate(final String value)
  5. parseDate(Long date, String format)
  6. parseDate(Object o)
  7. parseDate(Object str)
  8. parseDate(Object val)
  9. parseDate(SimpleDateFormat parser, String str, String[] parsePatterns)