mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 17:10:30 +00:00
utility class for iso 8601 dates
This commit is contained in:
parent
c5e31bc1c7
commit
d0cf992647
1 changed files with 59 additions and 0 deletions
59
enabler/test/de/schildbach/pte/util/Iso8601Format.java
Normal file
59
enabler/test/de/schildbach/pte/util/Iso8601Format.java
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012 the original author or authors.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.schildbach.pte.util;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andreas Schildbach
|
||||||
|
*/
|
||||||
|
public class Iso8601Format extends SimpleDateFormat
|
||||||
|
{
|
||||||
|
private Iso8601Format(String formatString)
|
||||||
|
{
|
||||||
|
super(formatString);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DateFormat newTimeFormat()
|
||||||
|
{
|
||||||
|
return new Iso8601Format("HH:mm:ss");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DateFormat newDateFormat()
|
||||||
|
{
|
||||||
|
return new Iso8601Format("yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DateFormat newDateTimeFormat()
|
||||||
|
{
|
||||||
|
return new Iso8601Format("yyyy-MM-dd HH:mm:ss");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String formatDateTime(final Date date)
|
||||||
|
{
|
||||||
|
return newDateTimeFormat().format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Date parseDateTime(final String date) throws ParseException
|
||||||
|
{
|
||||||
|
return newDateTimeFormat().parse(date);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue