1 /*
2 * Confluence BibSonomy plugin
3 * Copyright (C) 2007 Christian Schenk
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19 package org.christianschenk.confluence.plugin.bibsonomy.helper;
20
21 import java.text.ParseException;
22 import java.text.SimpleDateFormat;
23 import java.util.Date;
24
25 public class DateUtils {
26
27 /** This format fits the output from BibSonomy */
28 private static final String format = "yyyy-MM-dd'T'HH:mm:ss";
29
30 /**
31 * Parses a string and returns a Date object. If the string can't be parsed we'll ignore any
32 * exceptions and return an empty Date object.
33 *
34 * @param date
35 * String with date information
36 * @return Date object
37 */
38 public static Date parse(final String date) {
39 try {
40 return new SimpleDateFormat(format).parse(date);
41 } catch (final ParseException ignore) {
42 }
43 return new Date();
44 }
45 }