Java tutorial
//package com.java2s; /* * Copyright (c) 2011,2012,2013 UNIT4 Agresso AS. * * This file is part of Oxalis. * * Oxalis 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. * * Oxalis 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 Oxalis. If not, see <http://www.gnu.org/licenses/>. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final String rfc822DateFormat = "EEE, dd MMM yyyy HH:mm:ss Z"; public static Date parse(String dateString) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(rfc822DateFormat); Date parsedDate = null; try { parsedDate = simpleDateFormat.parse(dateString); } catch (ParseException e) { throw new IllegalArgumentException("Unable to parseMultipart '" + dateString + "' into a date using format '" + rfc822DateFormat + "'"); } return parsedDate; } }