Java Day of parseFromDays(String date)

Here you can find the source of parseFromDays(String date)

Description

Parses a string of the following format to a Date :

yyyy-MM-dd

License

Apache License

Parameter

Parameter Description
date The date to format

Return

The result

Declaration

public static Date parseFromDays(String date) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.google.common.base.Throwables;

public class Main {
    public static final String FORMAT_TO_DAYS = "yyyy-MM-dd";

    /**/* w w  w  . j a  va 2s  .  co m*/
      * Parses a string of the following format to a {@link Date}:
     * <p>
      * <code>
      * yyyy-MM-dd
      * </code>
     * 
     * @param date
     *            The date to format
     * 
     * @return The result
      */
    public static Date parseFromDays(String date) {
        return parse(getFormatToDays(), date);
    }

    private static Date parse(SimpleDateFormat format, String date) {
        try {
            return format.parse(date);
        } catch (ParseException e) {
            throw Throwables.propagate(e);
        }
    }

    /**
    * Returns a date format to the resolution of days:
    * <p>
    * <code>
    * yyyy-MM-dd
    * </code>
    * 
    * @return The result
    */
    public static SimpleDateFormat getFormatToDays() {
        return new SimpleDateFormat(FORMAT_TO_DAYS);
    }
}

Related

  1. parseDay(Date value, String defaultValue)
  2. parseDay(final String day)
  3. parseDay(int time)
  4. parseDay(String str, String type)
  5. parseDayTime(long ts)
  6. plusDay(Date date, int day)
  7. plusDays(Date date, int days)
  8. setDays(Date date, int amount)
  9. startOfDay(Date date, String format)