Here you can find the source of getDateFromFormat(String dtStr)
Parameter | Description |
---|---|
dtStr | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static Date getDateFromFormat(String dtStr) throws Exception
//package com.java2s; //License from project: Open Source License import java.time.*; import java.time.format.DateTimeFormatter; import java.util.Date; public class Main { /**/*from w w w .j a va2 s . co m*/ * Date formatter for MM-dd-yyyy */ private static final DateTimeFormatter df2 = DateTimeFormatter.ofPattern("MM-dd-yyyy"); /** * Expects date string as MM-dd-yyyy * * @param dtStr * @return * @throws Exception */ public static Date getDateFromFormat(String dtStr) throws Exception { LocalDate ld = LocalDate.parse(dtStr, df2); return localDateToSystemAdjustedStartOfDayDate(ld); } /** * Adjusts a LocalDate to Midnight of the say day (start of day). * * @param d * @return * @throws Exception */ public static Date localDateToSystemAdjustedStartOfDayDate(LocalDate d) throws Exception { LocalDateTime ldt = d.atStartOfDay(); return getSystemDefaultDate(ldt); } /** * Get local system Date from LocalDateTime * * @param ldt * @return * @throws Exception */ public static Date getSystemDefaultDate(LocalDateTime ldt) throws Exception { return Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); } }