Package ninja.utils

Class DateUtil


  • public class DateUtil
    extends Object
    • Constructor Detail

      • DateUtil

        public DateUtil()
    • Method Detail

      • formatForHttpHeader

        public static String formatForHttpHeader​(Date date)
        Can be used to format a date into http header compatible strings. It can be used to generate something like: Date: Wed, 05 Sep 2012 09:16:19 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT
        Parameters:
        date - The date to format
        Returns:
        a http header compatible string like "Thu, 01 Jan 1970 00:00:00 GMT"
      • formatForHttpHeader

        public static String formatForHttpHeader​(Long unixTime)
        Can be used to format a unix timestamp into http header compatible strings. It can be used to generate something like: Date: Wed, 05 Sep 2012 09:16:19 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT
        Parameters:
        date - The long (unixtime) to format
        Returns:
        a http header compatible string like "Thu, 01 Jan 1970 00:00:00 GMT"
      • parseHttpDateFormat

        public static Date parseHttpDateFormat​(String httpDateFormat)
                                        throws IllegalArgumentException
        Can be used to parse http times. For instance something like a http header Date: Tue, 26 Mar 2013 13:47:13 GMT INFO: consider the JodaTime based DateUtil.parseHttpDateFormatToDateTime(...) version
        Parameters:
        httpDateFormat - in http format: Date: Tue, 26 Mar 2013 13:47:13 GMT
        Returns:
        A nice "Date" object containing that http timestamp.
        Throws:
        ParseException - If something goes wrong.
        IllegalArgumentException
      • parseHttpDateFormatToDateTime

        public static org.joda.time.DateTime parseHttpDateFormatToDateTime​(String httpDateFormat)
                                                                    throws IllegalArgumentException
        Can be used to parse http times. For instance something like a http header Date: Tue, 26 Mar 2013 13:47:13 GMT
        Parameters:
        httpDateFormat - in http format: Date: Tue, 26 Mar 2013 13:47:13 GMT
        Returns:
        A nice "DateTime" (JodaTime) object containing that http timestamp.
        Throws:
        ParseException - If something goes wrong.
        IllegalArgumentException