Here you can find the source of dateToIsoDateString(@NotNull Date date)
Parameter | Description |
---|---|
date | the Date to format. Must not be null . |
public static String dateToIsoDateString(@NotNull Date date)
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main{ /**/*from w ww . j a v a 2s .c o m*/ * Converts a {@link java.util.Date} object to an ISO-formatted {@link String} representation of it. * * @param date the {@link java.util.Date} to format. Can be {@code null}. * @param fallback if {@code date} is {@code null}, this parameter decides the return value. * @return a formatted {@link String} of the form "yyyy-MM-dd HH:mm" * @throws IllegalArgumentException - if {@code date} is {@code null} and * {@code fallback} is invalid * @see #dateToIsoDateString(java.util.Date) * @see #isoDateStringToDate(String) */ @NotNull public static String dateToIsoDateString(@Nullable Date date, @NotNull DateFallback fallback) throws IllegalArgumentException { if (date != null) { return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date); } else if (fallback == DateFallback.EARLIEST) { return getEarliestDateString(); } throw new IllegalArgumentException( "date is null and fallback parameter is invalid!"); } /** * Converts a {@link Date} object to an ISO-formatted {@link String} representation of it. * * @param date the {@link Date} to format. Must not be {@code null}. * @return a formatted {@link String} of the form "yyyy-MM-dd HH:mm" * @see #dateToIsoDateString(Date, DateFallback) * @see #isoDateStringToDate(String) */ public static String dateToIsoDateString(@NotNull Date date) { return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date); } /** * Earliest possible date used in the app. */ @NotNull public static String getEarliestDateString() { return "1970-01-01 00:00"; } }