001    /*
002     * Created on Jan 22, 2011
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005     * the License. You may obtain a copy of the License at
006     *
007     * http://www.apache.org/licenses/LICENSE-2.0
008     *
009     * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010     * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011     * specific language governing permissions and limitations under the License.
012     *
013     * Copyright @2011 the original author or authors.
014     */
015    package org.fest.util;
016    
017    import java.text.SimpleDateFormat;
018    import java.util.*;
019    
020    /**
021     * @author Tomasz Nurkiewicz
022     * @author Joel Costigliola
023     */
024    public class Dates {
025    
026      /*
027       * ISO 8601 date-time format, example: "2003-04-01T13:01:02"
028       */
029      private static final String ISO_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
030    
031      /**
032       * Formats the given date using the ISO 8601 date-time format.
033       * @param date the date to format.
034       * @return the formatted date.
035       */
036            public static String format(Date date) {
037                    return new SimpleDateFormat(ISO_DATE_TIME_FORMAT).format(date);
038            }
039    
040      /**
041       * Formats the date of the given calendar using the ISO 8601 date-time format.
042       * @param calendar the calendar to format.
043       * @return the formatted calendar.
044       */
045            public static String format(Calendar calendar) {
046                    return format(calendar.getTime());
047            }
048    }